[app] Show better tips for repo load failure (#291)
This commit is contained in:
parent
a24235313a
commit
370a400abb
|
|
@ -24,8 +24,6 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -52,7 +50,6 @@ public class App extends Application {
|
|||
private static OkHttpClient okHttpClient;
|
||||
private static Cache okHttpCache;
|
||||
private SharedPreferences pref;
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public static App getInstance() {
|
||||
return instance;
|
||||
|
|
@ -126,8 +123,4 @@ public class App extends Application {
|
|||
}
|
||||
return okHttpCache;
|
||||
}
|
||||
|
||||
public void runOnUiThread(Runnable runnable) {
|
||||
handler.post(runnable);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
package io.github.lsposed.manager.repo;
|
||||
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
|
@ -80,7 +79,9 @@ public class RepoLoader {
|
|||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
App.getInstance().runOnUiThread(() -> Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show());
|
||||
for (Listener listener : listeners) {
|
||||
listener.onThrowable(e);
|
||||
}
|
||||
synchronized (this) {
|
||||
isLoading = false;
|
||||
}
|
||||
|
|
@ -105,9 +106,11 @@ public class RepoLoader {
|
|||
synchronized (this) {
|
||||
repoLoaded = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
App.getInstance().runOnUiThread(() -> Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show());
|
||||
} catch (Throwable t) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(t));
|
||||
for (Listener listener : listeners) {
|
||||
listener.onThrowable(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +128,9 @@ public class RepoLoader {
|
|||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
App.getInstance().runOnUiThread(() -> Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show());
|
||||
for (Listener listener : listeners) {
|
||||
listener.onThrowable(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -142,9 +147,11 @@ public class RepoLoader {
|
|||
for (Listener listener : listeners) {
|
||||
listener.moduleReleasesLoaded(module);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
App.getInstance().runOnUiThread(() -> Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show());
|
||||
} catch (Throwable t) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(t));
|
||||
for (Listener listener : listeners) {
|
||||
listener.onThrowable(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,5 +180,7 @@ public class RepoLoader {
|
|||
void repoLoaded();
|
||||
|
||||
void moduleReleasesLoaded(OnlineModule module);
|
||||
|
||||
void onThrowable(Throwable t);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,11 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -90,6 +93,13 @@ public class RepoActivity extends ListActivity implements RepoLoader.Listener {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThrowable(Throwable t) {
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
Snackbar.make(binding.snackbar, getString(R.string.repo_load_failed, t.getLocalizedMessage()), Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
|
|
@ -156,12 +157,23 @@ public class RepoItemActivity extends BaseActivity implements RepoLoader.Listene
|
|||
this.module = module;
|
||||
if (releaseAdapter != null) {
|
||||
runOnUiThread(() -> {
|
||||
if (module.getReleases().size() == 1) {
|
||||
Snackbar.make(binding.snackbar, R.string.module_release_no_more, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
releaseAdapter.loadItems();
|
||||
releaseAdapter.notifyDataSetChanged();
|
||||
});
|
||||
if (module.getReleases().size() == 1) {
|
||||
Snackbar.make(binding.snackbar, R.string.module_release_no_more, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThrowable(Throwable t) {
|
||||
if (releaseAdapter != null) {
|
||||
runOnUiThread(() -> {
|
||||
releaseAdapter.loadItems();
|
||||
});
|
||||
}
|
||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
Snackbar.make(binding.snackbar, getString(R.string.repo_load_failed, t.getLocalizedMessage()), Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +294,8 @@ public class RepoItemActivity extends BaseActivity implements RepoLoader.Listene
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
if (position == items.size()) {
|
||||
holder.progress.setVisibility(View.GONE);
|
||||
holder.title.setVisibility(View.VISIBLE);
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (holder.progress.getVisibility() == View.GONE) {
|
||||
holder.title.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -183,4 +183,6 @@
|
|||
<string name="module_uninstall_message">要卸载此模块吗?</string>
|
||||
<string name="module_uninstalled">已卸载%1$s</string>
|
||||
<string name="module_uninstall_failed">卸载失败</string>
|
||||
<string name="repo_load_failed">模块仓库加载失败:%s</string>
|
||||
<string name="repo_load_more_failed">更旧的版本加载失败:%s</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -160,6 +160,8 @@
|
|||
<string name="refresh">Refresh</string>
|
||||
<string name="module_release_load_more">Show older versions</string>
|
||||
<string name="module_release_no_more">No more release</string>
|
||||
<string name="repo_load_failed">Failed to load module repo: %s</string>
|
||||
<string name="repo_load_more_failed">Failed to load older versions: %s</string>
|
||||
|
||||
|
||||
<string name="about_source" translatable="false">https://github.com/LSPosed/LSPosed/</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue