From 45b8c6fcc34e35bbf19eb3a6175a5fcb93453dea Mon Sep 17 00:00:00 2001 From: mkrupczak3 Date: Sat, 15 Jun 2019 17:27:53 -0400 Subject: [PATCH] Change hack to a forced full app "relaunch" on first run --- .../net/nullsum/freedoom/EntryActivity.java | 7 +++++ .../freedoom/LaunchFragmentGZdoom.java | 28 ++++++++++++++----- .../main/java/net/nullsum/freedoom/Utils.java | 5 ---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/doom/src/main/java/net/nullsum/freedoom/EntryActivity.java b/doom/src/main/java/net/nullsum/freedoom/EntryActivity.java index fc7da726..a6d379cb 100644 --- a/doom/src/main/java/net/nullsum/freedoom/EntryActivity.java +++ b/doom/src/main/java/net/nullsum/freedoom/EntryActivity.java @@ -6,6 +6,7 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Bundle; @@ -65,6 +66,12 @@ protected void onCreate(Bundle savedInstanceState) { } + public void restart(){ + Intent intent = new Intent(this, EntryActivity.class); + this.startActivity(intent); + this.finishAffinity(); + } + @Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restore the previously serialized current tab position. diff --git a/doom/src/main/java/net/nullsum/freedoom/LaunchFragmentGZdoom.java b/doom/src/main/java/net/nullsum/freedoom/LaunchFragmentGZdoom.java index df116395..99071bc8 100644 --- a/doom/src/main/java/net/nullsum/freedoom/LaunchFragmentGZdoom.java +++ b/doom/src/main/java/net/nullsum/freedoom/LaunchFragmentGZdoom.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -85,15 +86,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, // https://stackoverflow.com/questions/15262747/refresh-or-force-redraw-the-fragment // simple refresh of wad list - listAdapter.notifyDataSetChanged(); + (new Handler()).postDelayed(this::listRefreshHack, 10000); + - // // Extremely aggressive redraw of wad list - // listview.invalidateViews(); - // Aggressive hack which forces the entire fragment to redraw - FragmentTransaction tr = getFragmentManager().beginTransaction(); - tr.replace(((ViewGroup)getView().getParent()).getId(), this); - tr.commit(); // END HACK } @@ -154,6 +150,24 @@ public void resultResult(String result) { return mainView; } + void listRefreshHack() { + Log.d(LOG, "HACK refreshing wad list"); + + // Doesn't work + listAdapter.notifyDataSetChanged(); + +// // Extremely aggressive redraw of wad list +// listview.invalidateViews(); + + // Force the main activity to respawn (nuclear option) @TODO fix me + ((EntryActivity)getActivity()).restart(); + +//// Aggressive hack which forces the entire fragment to redraw +// FragmentTransaction tr = getFragmentManager().beginTransaction(); +// tr.replace(((ViewGroup)getView().getParent()).getId(), this); +// tr.commit(); + } + void startGame(final String base, boolean ignoreMusic, final String moreArgs) { //Check gzdoom.pk3 wad exists //File extrawad = new File(base + "/gzdoom.pk3"); diff --git a/doom/src/main/java/net/nullsum/freedoom/Utils.java b/doom/src/main/java/net/nullsum/freedoom/Utils.java index 1698954a..17aa4b1a 100644 --- a/doom/src/main/java/net/nullsum/freedoom/Utils.java +++ b/doom/src/main/java/net/nullsum/freedoom/Utils.java @@ -91,11 +91,6 @@ static void copyFreedoomFilesToSD(Activity responsibleActivity) { Utils.copyAsset(responsibleActivity, "brightmaps.pk3", fullModDir); } - tester = new File( fullModDir + "/" + "gzdoom.pk3"); - if (!tester.exists()) { - Utils.copyAsset(responsibleActivity, "gzdoom.pk3", fullModDir); - } - tester = new File( fullModDir + "/" + "lights.pk3"); if (!tester.exists()) { Utils.copyAsset(responsibleActivity, "lights.pk3", fullModDir);