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