added donate snackbar
This commit is contained in:
parent
6fea1b7b8e
commit
9ec29e3936
4 changed files with 73 additions and 4 deletions
|
@ -74,4 +74,28 @@ public class Settings {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getBoolean("ignore_checksum", false);
|
||||
}
|
||||
|
||||
public static void setPatchingSuccessful(Context context, Boolean isSuccessful) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean("patching_successful", isSuccessful);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean getPatchingSuccessful(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getBoolean("patching_successful", false);
|
||||
}
|
||||
|
||||
public static void setDontShowDonateSnackbarCount(Context context, int count) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt("dont_show_donate_snackbar", count);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static int getDontShowDonateSnackbarCount(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getInt("dont_show_donate_snackbar", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ public class WorkerService extends IntentService {
|
|||
if ("ppf".equals(ext))
|
||||
Utils.copyFile(this, romFile, outputFile);
|
||||
patcher.apply(Settings.getIgnoreChecksum(this));
|
||||
Settings.setPatchingSuccessful(this, true);
|
||||
} catch (PatchException | IOException e) {
|
||||
if (Utils.getFreeSpace(outputFile.getParentFile()) == 0) {
|
||||
errorMsg = getString(R.string.notify_error_not_enough_space);
|
||||
|
@ -219,6 +220,7 @@ public class WorkerService extends IntentService {
|
|||
|
||||
try {
|
||||
patcher.create();
|
||||
Settings.setPatchingSuccessful(this, true);
|
||||
} catch (PatchException | IOException e) {
|
||||
if (Utils.getFreeSpace(patchFile.getParentFile()) == 0) {
|
||||
errorMsg = getString(R.string.notify_error_not_enough_space);
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
@ -40,6 +41,7 @@ import android.view.View;
|
|||
|
||||
import org.emunix.unipatcher.BuildConfig;
|
||||
import org.emunix.unipatcher.R;
|
||||
import org.emunix.unipatcher.Settings;
|
||||
import org.emunix.unipatcher.UniPatcher;
|
||||
import org.emunix.unipatcher.ui.fragment.ActionFragment;
|
||||
import org.emunix.unipatcher.ui.fragment.CreatePatchFragment;
|
||||
|
@ -47,6 +49,8 @@ import org.emunix.unipatcher.ui.fragment.PatchingFragment;
|
|||
import org.emunix.unipatcher.ui.fragment.SmdFixChecksumFragment;
|
||||
import org.emunix.unipatcher.ui.fragment.SnesSmcHeaderFragment;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static android.support.v7.app.AppCompatDelegate.MODE_NIGHT_AUTO;
|
||||
import static android.support.v7.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||
import static android.support.v7.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||
|
@ -78,8 +82,6 @@ public class MainActivity extends AppCompatActivity
|
|||
if (fragment != null) {
|
||||
boolean ret = fragment.runAction();
|
||||
}
|
||||
//Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
// .setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -91,6 +93,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
parseArgument();
|
||||
showDonateSnackbar();
|
||||
}
|
||||
|
||||
private void setTheme() {
|
||||
|
@ -132,8 +135,7 @@ public class MainActivity extends AppCompatActivity
|
|||
} else if (id == R.id.nav_rate) {
|
||||
rateApp();
|
||||
} else if (id == R.id.nav_donate) {
|
||||
Intent donateIntent = new Intent(this, DonateActivity.class);
|
||||
startActivity(donateIntent);
|
||||
showDonateActivity();
|
||||
} else if (id == R.id.nav_share) {
|
||||
shareApp();
|
||||
} else if (id == R.id.nav_help) {
|
||||
|
@ -175,6 +177,45 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void showDonateSnackbar() {
|
||||
// don't show snackbar if the user did not patch the file successfully
|
||||
if (!Settings.getPatchingSuccessful(this))
|
||||
return;
|
||||
|
||||
// don't show snackbar some time if the user swiped off it before
|
||||
int count = Settings.getDontShowDonateSnackbarCount(this);
|
||||
if (count != 0) {
|
||||
Settings.setDontShowDonateSnackbarCount(this, --count);
|
||||
return;
|
||||
}
|
||||
|
||||
// don't show snackbar each time you open the application
|
||||
if (new Random().nextInt(6) != 0)
|
||||
return;
|
||||
|
||||
Snackbar.make(findViewById(R.id.content_frame), R.string.main_activity_donate_snackbar_text, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.main_activity_donate_snackbar_button, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDonateActivity();
|
||||
}
|
||||
})
|
||||
.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onDismissed(Snackbar snackbar, int event) {
|
||||
if (event == Snackbar.Callback.DISMISS_EVENT_SWIPE) {
|
||||
Settings.setDontShowDonateSnackbarCount(getApplicationContext(), 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
).show();
|
||||
}
|
||||
|
||||
private void showDonateActivity() {
|
||||
Intent donateIntent = new Intent(this, DonateActivity.class);
|
||||
startActivity(donateIntent);
|
||||
}
|
||||
|
||||
private void shareApp() {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
<string name="main_activity_toast_rom_not_selected">No ROM file selected</string>
|
||||
<string name="main_activity_toast_patch_not_selected">No patch file selected</string>
|
||||
<string name="main_activity_toast_archives_not_supported">Archive should be unpacked in an external program</string>
|
||||
<string name="main_activity_donate_snackbar_text">Support the development of UniPatcher by making a donation</string>
|
||||
<string name="main_activity_donate_snackbar_button">Donate</string>
|
||||
|
||||
<!-- Rename dialog -->
|
||||
<string name="dialog_rename_title">Rename</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue