Refactoring
This commit is contained in:
parent
0a871af744
commit
693cc9b49f
7 changed files with 29 additions and 30 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
package com.kabouzeid.gramophone;
|
package com.kabouzeid.gramophone;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.core.CrashlyticsCore;
|
import com.crashlytics.android.core.CrashlyticsCore;
|
||||||
|
import com.kabouzeid.gramophone.appshortcuts.DynamicShortcutManager;
|
||||||
|
|
||||||
import io.fabric.sdk.android.Fabric;
|
import io.fabric.sdk.android.Fabric;
|
||||||
|
|
||||||
|
|
@ -22,5 +24,10 @@ public class App extends Application {
|
||||||
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
||||||
.build();
|
.build();
|
||||||
Fabric.with(this, crashlyticsKit);
|
Fabric.with(this, crashlyticsKit);
|
||||||
|
|
||||||
|
//Set up dynamic shortcuts
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
|
new DynamicShortcutManager(this).initDynamicShortcuts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.content.pm.ShortcutManager;
|
import android.content.pm.ShortcutManager;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
|
@ -13,7 +12,6 @@ import com.kabouzeid.gramophone.appshortcuts.shortcuttype.LastAddedShortcutType;
|
||||||
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.ShuffleAllShortcutType;
|
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.ShuffleAllShortcutType;
|
||||||
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.TopTracksShortcutType;
|
import com.kabouzeid.gramophone.appshortcuts.shortcuttype.TopTracksShortcutType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -24,12 +22,12 @@ import java.util.List;
|
||||||
@TargetApi(Build.VERSION_CODES.N_MR1)
|
@TargetApi(Build.VERSION_CODES.N_MR1)
|
||||||
public class DynamicShortcutManager {
|
public class DynamicShortcutManager {
|
||||||
|
|
||||||
Context mContext;
|
private Context context;
|
||||||
ShortcutManager shortcutManager;
|
private ShortcutManager shortcutManager;
|
||||||
|
|
||||||
public DynamicShortcutManager(Context context) {
|
public DynamicShortcutManager(Context context) {
|
||||||
mContext = context;
|
this.context = context;
|
||||||
shortcutManager = mContext.getSystemService(ShortcutManager.class);
|
shortcutManager = this.context.getSystemService(ShortcutManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
|
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
|
||||||
|
|
@ -53,9 +51,9 @@ public class DynamicShortcutManager {
|
||||||
|
|
||||||
public List<ShortcutInfo> getDefaultShortcuts() {
|
public List<ShortcutInfo> getDefaultShortcuts() {
|
||||||
return (Arrays.asList(
|
return (Arrays.asList(
|
||||||
new ShuffleAllShortcutType(mContext).getShortcutInfo(),
|
new ShuffleAllShortcutType(context).getShortcutInfo(),
|
||||||
new TopTracksShortcutType(mContext).getShortcutInfo(),
|
new TopTracksShortcutType(context).getShortcutInfo(),
|
||||||
new LastAddedShortcutType(mContext).getShortcutInfo()
|
new LastAddedShortcutType(context).getShortcutInfo()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ public abstract class BaseShortcutType {
|
||||||
|
|
||||||
static final String ID_PREFIX = "com.kabouzeid.gramophone.appshortcuts.id.";
|
static final String ID_PREFIX = "com.kabouzeid.gramophone.appshortcuts.id.";
|
||||||
|
|
||||||
Context mContext;
|
Context context;
|
||||||
|
|
||||||
public BaseShortcutType(Context context) {
|
public BaseShortcutType(Context context) {
|
||||||
mContext = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ public abstract class BaseShortcutType {
|
||||||
*/
|
*/
|
||||||
Intent getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType shortcutType) {
|
Intent getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType shortcutType) {
|
||||||
//Create a new intent to launch MainActivity
|
//Create a new intent to launch MainActivity
|
||||||
Intent intent = new Intent(mContext, AppShortcutLauncherActivity.class);
|
Intent intent = new Intent(context, AppShortcutLauncherActivity.class);
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
|
||||||
//Create a bundle to store instructions for AppShortcutLauncherActivity
|
//Create a bundle to store instructions for AppShortcutLauncherActivity
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ public final class LastAddedShortcutType extends BaseShortcutType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShortcutInfo getShortcutInfo() {
|
public ShortcutInfo getShortcutInfo() {
|
||||||
return new ShortcutInfo.Builder(mContext, getId())
|
return new ShortcutInfo.Builder(context, getId())
|
||||||
.setShortLabel(mContext.getString(R.string.app_shortcut_last_added_short))
|
.setShortLabel(context.getString(R.string.app_shortcut_last_added_short))
|
||||||
.setLongLabel(mContext.getString(R.string.app_shortcut_last_added_long))
|
.setLongLabel(context.getString(R.string.app_shortcut_last_added_long))
|
||||||
.setIcon(AppShortcutIconGenerator.generateThemedIcon(mContext, R.drawable.ic_app_shortcut_last_added))
|
.setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_last_added))
|
||||||
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.LAST_ADDED))
|
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.LAST_ADDED))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ public final class ShuffleAllShortcutType extends BaseShortcutType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShortcutInfo getShortcutInfo() {
|
public ShortcutInfo getShortcutInfo() {
|
||||||
return new ShortcutInfo.Builder(mContext, getId())
|
return new ShortcutInfo.Builder(context, getId())
|
||||||
.setShortLabel(mContext.getString(R.string.app_shortcut_shuffle_all_short))
|
.setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short))
|
||||||
.setLongLabel(mContext.getString(R.string.app_shortcut_shuffle_all_long))
|
.setLongLabel(context.getString(R.string.app_shortcut_shuffle_all_long))
|
||||||
.setIcon(AppShortcutIconGenerator.generateThemedIcon(mContext, R.drawable.ic_app_shortcut_shuffle_all))
|
.setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_shuffle_all))
|
||||||
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.SHUFFLE_ALL))
|
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.SHUFFLE_ALL))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ public final class TopTracksShortcutType extends BaseShortcutType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShortcutInfo getShortcutInfo() {
|
public ShortcutInfo getShortcutInfo() {
|
||||||
return new ShortcutInfo.Builder(mContext, getId())
|
return new ShortcutInfo.Builder(context, getId())
|
||||||
.setShortLabel(mContext.getString(R.string.app_shortcut_top_tracks_short))
|
.setShortLabel(context.getString(R.string.app_shortcut_top_tracks_short))
|
||||||
.setLongLabel(mContext.getString(R.string.app_shortcut_top_tracks_long))
|
.setLongLabel(context.getString(R.string.app_shortcut_top_tracks_long))
|
||||||
.setIcon(AppShortcutIconGenerator.generateThemedIcon(mContext, R.drawable.ic_app_shortcut_top_tracks))
|
.setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_top_tracks))
|
||||||
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.TOP_TRACKS))
|
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.ShortcutType.TOP_TRACKS))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import com.kabouzeid.appthemehelper.ThemeStore;
|
||||||
import com.kabouzeid.appthemehelper.util.ATHUtil;
|
import com.kabouzeid.appthemehelper.util.ATHUtil;
|
||||||
import com.kabouzeid.appthemehelper.util.NavigationViewUtil;
|
import com.kabouzeid.appthemehelper.util.NavigationViewUtil;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
import com.kabouzeid.gramophone.appshortcuts.DynamicShortcutManager;
|
|
||||||
import com.kabouzeid.gramophone.dialogs.ChangelogDialog;
|
import com.kabouzeid.gramophone.dialogs.ChangelogDialog;
|
||||||
import com.kabouzeid.gramophone.dialogs.DonationsDialog;
|
import com.kabouzeid.gramophone.dialogs.DonationsDialog;
|
||||||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||||
|
|
@ -113,11 +112,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity {
|
||||||
if (!checkShowIntro()) {
|
if (!checkShowIntro()) {
|
||||||
checkShowChangelog();
|
checkShowChangelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set up dynamic shortcuts
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
|
||||||
new DynamicShortcutManager(this).initDynamicShortcuts();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMusicChooser(int key) {
|
private void setMusicChooser(int key) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue