Skip to content

Commit

Permalink
Custom filename for extracted APKs
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Jun 2, 2015
1 parent 622cdae commit 40d59d2
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 9 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/javiersantos/mlmanager/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
Expand All @@ -25,6 +26,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private Preference prefVersion, prefDeleteAll, prefDefaultValues, prefNavigationBlack;
private AmbilWarnaPreference prefPrimaryColor, prefFABColor;
private CheckBoxPreference prefFABShow;
private ListPreference prefCustomFilename;
private String versionName;
private int versionCode;
private Context context;
Expand All @@ -46,6 +48,7 @@ public void onCreate(Bundle savedInstanceState) {
prefDeleteAll = findPreference("prefDeleteAll");
prefDefaultValues = findPreference("prefDefaultValues");
prefNavigationBlack = findPreference("prefNavigationBlack");
prefCustomFilename = (ListPreference) findPreference("prefCustomFilename");

setInitialConfiguration();

Expand All @@ -62,6 +65,9 @@ public boolean onPreferenceClick(Preference preference) {
}
});

// prefCustomFilename
setCustomFilenameSummary();

// prefDeleteAll
prefDeleteAll.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down Expand Up @@ -109,10 +115,18 @@ private void setInitialConfiguration() {
}
}

private void setCustomFilenameSummary() {
int filenameValue = new Integer(appPreferences.getCustomFilename())-1;
prefCustomFilename.setSummary(getResources().getStringArray(R.array.filenameEntries)[filenameValue]);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);

if (pref == prefCustomFilename) {
setCustomFilenameSummary();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AppPreferences {
public static final String KeyFABColor = "prefFABColor";
public static final String KeyFABShow = "prefFABShow";
public static final String KeyNavigationBlack = "prefNavigationBlack";
public static final String KeyCustomFilename = "prefCustomFilename";

public AppPreferences(Context context) {
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down Expand Up @@ -63,4 +64,12 @@ public void setFABShowPref(Boolean res) {
editor.commit();
}

public String getCustomFilename() {
return sharedPreferences.getString(KeyCustomFilename, "1");
}
public void setCustomFilename(String res) {
editor.putString(KeyCustomFilename, res);
editor.commit();
}

}
27 changes: 24 additions & 3 deletions app/src/main/java/com/javiersantos/mlmanager/utils/UtilsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@
import android.os.Environment;
import android.util.Log;

import com.javiersantos.mlmanager.AppInfo;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

public class UtilsApp {
// Load Settings
private static AppPreferences appPreferences;

public static File getAppFolder() {
return new File(Environment.getExternalStorageDirectory() + "/MLManager");
}

public static File copyFile(String apk, String source) {
File initialFile = new File(source);
File finalFile = new File(getAppFolder().getPath() + "/" + apk + ".apk");
public static File copyFile(Context context, AppInfo appInfo) {
appPreferences = new AppPreferences(context);

File initialFile = new File(appInfo.source);
File finalFile;

switch (appPreferences.getCustomFilename()) {
case "1":
finalFile = new File(getAppFolder().getPath() + "/" + appInfo.apk + "_" + appInfo.version + ".apk");
break;
case "2":
finalFile = new File(getAppFolder().getPath() + "/" + appInfo.name + "_" + appInfo.version + ".apk");
break;
case "4":
finalFile = new File(getAppFolder().getPath() + "/" + appInfo.name + ".apk");
break;
default:
finalFile = new File(getAppFolder().getPath() + "/" + appInfo.apk + ".apk");
break;
}

try {
FileUtils.copyFile(initialFile, finalFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@
import android.support.v4.content.ContextCompat;

import com.afollestad.materialdialogs.MaterialDialog;
import com.javiersantos.mlmanager.AppInfo;
import com.javiersantos.mlmanager.R;

public class UtilsDialog {
private static MaterialDialog materialDialog;
private static AppPreferences appPreferences;

public static MaterialDialog.Builder showSavedDialog(Context context, AppInfo appInfo) {
appPreferences = new AppPreferences(context);
String filename;

switch (appPreferences.getCustomFilename()) {
case "1":
filename = appInfo.apk + "_" + appInfo.version;
break;
case "2":
filename = appInfo.name + "_" + appInfo.version;
break;
case "4":
filename = appInfo.name;
break;
default:
filename = appInfo.apk;
break;
}

public static MaterialDialog.Builder showSavedDialog(Context context, String name, String apk) {
MaterialDialog.Builder materialDialog = new MaterialDialog.Builder(context)
.title(String.format(context.getResources().getString(R.string.dialog_saved), name))
.content(String.format(context.getResources().getString(R.string.dialog_saved_description), name, apk))
.title(String.format(context.getResources().getString(R.string.dialog_saved), appInfo.name))
.content(String.format(context.getResources().getString(R.string.dialog_saved_description), appInfo.name, filename))
.positiveText(context.getResources().getString(R.string.button_ok))
.callback(new MaterialDialog.ButtonCallback() {
@Override
Expand Down Expand Up @@ -41,9 +60,9 @@ public void onPositive(MaterialDialog dialog) {
return materialBuilder;
}

public static MaterialDialog.Builder showIndeterminateProgressDialog(Context context, String name) {
public static MaterialDialog.Builder showIndeterminateProgressDialog(Context context, AppInfo appInfo) {
MaterialDialog.Builder materialBuilder = new MaterialDialog.Builder(context)
.title(String.format(context.getResources().getString(R.string.dialog_saving), name))
.title(String.format(context.getResources().getString(R.string.dialog_saving), appInfo.name))
.content(context.getResources().getString(R.string.dialog_saving_description))
.cancelable(false)
.progress(true, 0);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values-es/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="filenameEntries">
<item>Source + Versión</item>
<item>Nombre + Versión</item>
<item>Source</item>
<item>Nombe</item>
</string-array>
</resources>
15 changes: 15 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="filenameEntries">
<item>Source + Version</item>
<item>Name + Version</item>
<item>Source</item>
<item>Name</item>
</string-array>
<string-array name="filenameValues">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
android:key="prefDeleteAll"
android:title="@string/settings_delete_all"
android:summary="@string/settings_delete_all_description" />
<ListPreference
android:key="prefCustomFilename"
android:title="@string/settings_custom_filename"
android:entries="@array/filenameEntries"
android:entryValues="@array/filenameValues"
android:defaultValue="1" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_customizations">
Expand Down

0 comments on commit 40d59d2

Please sign in to comment.