Fixed dependencies on old base

This commit is contained in:
Viktor De Pasquale 2019-04-16 19:21:20 +02:00
parent 5330dda9f8
commit 0568ae5391
3 changed files with 23 additions and 19 deletions

View File

@ -20,7 +20,8 @@ import com.topjohnwu.magisk.data.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.model.download.DownloadModuleService;
import com.topjohnwu.magisk.model.entity.Module;
import com.topjohnwu.magisk.model.entity.Repo;
import com.topjohnwu.magisk.ui.base.BaseActivity;
import com.topjohnwu.magisk.ui.base.IBaseLeanback;
import com.topjohnwu.magisk.ui.base.MagiskActivity;
import com.topjohnwu.magisk.utils.Event;
import com.topjohnwu.magisk.view.MarkDownWindow;
import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog;
@ -118,15 +119,15 @@ public class ReposAdapter
.setMessage(context.getString(R.string.repo_install_msg, repo.getDownloadFilename()))
.setCancelable(true)
.setPositiveButton(R.string.install, (d, i) ->
startDownload((BaseActivity) context, repo, true))
startDownload((MagiskActivity) context, repo, true))
.setNeutralButton(R.string.download, (d, i) ->
startDownload((BaseActivity) context, repo, false))
startDownload((MagiskActivity) context, repo, false))
.setNegativeButton(R.string.no_thanks, null)
.show();
});
}
private void startDownload(BaseActivity activity, Repo repo, Boolean install) {
private <Ctxt extends Context & IBaseLeanback> void startDownload(Ctxt activity, Repo repo, Boolean install) {
activity.runWithExternalRW(() -> {
Intent intent = new Intent(activity, ClassMap.get(DownloadModuleService.class))
.putExtra("repo", repo).putExtra("install", install);

View File

@ -26,11 +26,11 @@ import androidx.collection.SparseArrayCompat;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public abstract class BaseActivity extends AppCompatActivity implements Event.AutoListener {
public abstract class BaseActivity extends AppCompatActivity implements Event.AutoListener, IBaseLeanback {
static int[] EMPTY_INT_ARRAY = new int[0];
private SparseArrayCompat<ActivityResultListener> resultListeners = new SparseArrayCompat<>();
private final SparseArrayCompat<ActivityResultListener> resultListeners = new SparseArrayCompat<>();
public App app = App.self;
@Override
@ -87,14 +87,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Event.Au
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
public void runWithExternalRW(Runnable callback) {
runWithPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, callback);
}
public void runWithPermissions(String[] permissions, Runnable callback) {
runWithPermissions(this, permissions, callback);
}
public static void runWithPermissions(Context context, String[] permissions, Runnable callback) {
boolean granted = true;
for (String perm : permissions) {
@ -109,12 +101,22 @@ public abstract class BaseActivity extends AppCompatActivity implements Event.Au
if (context instanceof BaseActivity) {
BaseActivity activity = (BaseActivity) context;
int code = callback.hashCode() & 0xFFFF;
activity.resultListeners.put(code, ((i, d) -> callback.run()));
activity.resultListeners.put(code, (i, d) -> callback.run());
ActivityCompat.requestPermissions(activity, permissions, code);
}
}
}
@Override
public final void runWithExternalRW(Runnable callback) {
runWithPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, callback);
}
@Override
public final void runWithPermissions(String[] permissions, Runnable callback) {
runWithPermissions(this, permissions, callback);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
onActivityResultListener(requestCode, resultCode, data);
@ -128,9 +130,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Event.Au
}
}
public void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) {
@Override
public final void startActivityForResult(Intent intent, int requestCode, ActivityResultListener listener) {
resultListeners.put(requestCode, listener);
super.startActivityForResult(intent, requestCode);
startActivityForResult(intent, requestCode);
}
@Override

View File

@ -40,11 +40,11 @@ public abstract class BaseFragment extends Fragment implements Event.AutoListene
public void startActivityForResult(Intent intent, int requestCode,
BaseActivity.ActivityResultListener listener) {
((BaseActivity) requireActivity()).startActivityForResult(intent, requestCode, listener);
((IBaseLeanback) requireActivity()).startActivityForResult(intent, requestCode, listener);
}
protected void runWithExternalRW(Runnable callback) {
((BaseActivity) requireActivity()).runWithExternalRW(callback);
((IBaseLeanback) requireActivity()).runWithExternalRW(callback);
}
@Override