|
| 1 | +package com.mcal.disassembler.activities; |
| 2 | + |
| 3 | +import android.Manifest; |
| 4 | +import android.annotation.SuppressLint; |
| 5 | +import android.annotation.TargetApi; |
| 6 | +import android.content.Intent; |
| 7 | +import android.content.pm.PackageManager; |
| 8 | +import android.net.Uri; |
| 9 | +import android.os.Build; |
| 10 | +import android.os.Bundle; |
| 11 | +import android.provider.Settings; |
| 12 | +import android.view.Menu; |
| 13 | +import android.view.MenuItem; |
| 14 | +import android.view.View; |
| 15 | +import android.widget.LinearLayout; |
| 16 | + |
| 17 | +import androidx.annotation.NonNull; |
| 18 | +import androidx.appcompat.app.AppCompatActivity; |
| 19 | +import androidx.appcompat.app.AppCompatDelegate; |
| 20 | + |
| 21 | +import com.mcal.disassembler.BuildConfig; |
| 22 | +import com.mcal.disassembler.R; |
| 23 | +import com.mcal.disassembler.data.Constants; |
| 24 | +import com.mcal.disassembler.data.Preferences; |
| 25 | +import com.mcal.disassembler.iap.DataWrappers; |
| 26 | +import com.mcal.disassembler.iap.IapConnector; |
| 27 | +import com.mcal.disassembler.iap.PurchaseServiceListener; |
| 28 | +import com.mcal.disassembler.iap.SubscriptionServiceListener; |
| 29 | +import com.mcal.disassembler.util.AdsAdmob; |
| 30 | +import com.mcal.disassembler.view.CenteredToolBar; |
| 31 | + |
| 32 | +import org.jetbrains.annotations.NotNull; |
| 33 | + |
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Map; |
| 38 | + |
| 39 | +import kotlin.Unit; |
| 40 | +import kotlin.jvm.functions.Function0; |
| 41 | + |
| 42 | +public class Main extends AppCompatActivity { |
| 43 | + |
| 44 | + public static int ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE = 5469; |
| 45 | + public static LinearLayout adLayout; |
| 46 | + |
| 47 | + static { |
| 48 | + System.loadLibrary("disassembler"); |
| 49 | + } |
| 50 | + |
| 51 | + private IapConnector iapConnector; |
| 52 | + |
| 53 | + @Override |
| 54 | + public void onCreate(Bundle savedInstanceState) { |
| 55 | + super.onCreate(savedInstanceState); |
| 56 | + setContentView(R.layout.main); |
| 57 | + setupToolbar(getString(R.string.app_name)); |
| 58 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 59 | + if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) != PackageManager.PERMISSION_GRANTED) { |
| 60 | + requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Settings.ACTION_MANAGE_OVERLAY_PERMISSION}, 1); |
| 61 | + } |
| 62 | + } |
| 63 | + AdsAdmob.loadInterestialAd(this); |
| 64 | + adLayout = findViewById(R.id.ad_view); |
| 65 | + adLayout.addView(AdsAdmob.getBanner(this)); |
| 66 | + checkPermission(); |
| 67 | + List<String> nonConsumablesList = Collections.singletonList("premium"); |
| 68 | + List<String> consumablesList = Arrays.asList("donate_disassembler", "moderate", "quite", "plenty", "yearly"); |
| 69 | + List<String> subsList = Collections.singletonList("subscription"); |
| 70 | + |
| 71 | + iapConnector = new IapConnector( |
| 72 | + this, |
| 73 | + nonConsumablesList, |
| 74 | + consumablesList, |
| 75 | + subsList, |
| 76 | + Constants.LK, |
| 77 | + BuildConfig.DEBUG |
| 78 | + ); |
| 79 | + |
| 80 | + iapConnector.addPurchaseListener(new PurchaseServiceListener() { |
| 81 | + public void onPricesUpdated(@NotNull Map<String, String> iapKeyPrices) { |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + public void onProductPurchased(DataWrappers.@NotNull PurchaseInfo purchaseInfo) { |
| 86 | + if (purchaseInfo.getSku().equals("donate_disassembler")) { |
| 87 | + |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + public void onProductRestored(DataWrappers.@NotNull PurchaseInfo purchaseInfo) { |
| 92 | + |
| 93 | + } |
| 94 | + }); |
| 95 | + iapConnector.addSubscriptionListener(new SubscriptionServiceListener() { |
| 96 | + public void onSubscriptionRestored(DataWrappers.@NotNull PurchaseInfo purchaseInfo) { |
| 97 | + } |
| 98 | + |
| 99 | + public void onSubscriptionPurchased(DataWrappers.@NotNull PurchaseInfo purchaseInfo) { |
| 100 | + if (purchaseInfo.getSku().equals("subscription")) { |
| 101 | + |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + public void onPricesUpdated(@NotNull Map<String, String> iapKeyPrices) { |
| 106 | + |
| 107 | + } |
| 108 | + }); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 113 | + getMenuInflater().inflate(R.menu.menu_main, menu); |
| 114 | + return super.onCreateOptionsMenu(menu); |
| 115 | + } |
| 116 | + |
| 117 | + @SuppressLint("WrongConstant") |
| 118 | + @Override |
| 119 | + public boolean onOptionsItemSelected(@NonNull MenuItem item) { |
| 120 | + if (item.getItemId() == R.id.night_mode) { |
| 121 | + if (Preferences.isNightModeEnabled()) { |
| 122 | + Preferences.setNightModeEnabled(false); |
| 123 | + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
| 124 | + getDelegate().applyDayNight(); |
| 125 | + } else { |
| 126 | + Preferences.setNightModeEnabled(true); |
| 127 | + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
| 128 | + getDelegate().applyDayNight(); |
| 129 | + } |
| 130 | + } |
| 131 | + return super.onOptionsItemSelected(item); |
| 132 | + } |
| 133 | + |
| 134 | + @SuppressWarnings("ConstantConditions") |
| 135 | + private void setupToolbar(String title) { |
| 136 | + CenteredToolBar toolbar = findViewById(R.id.toolbar); |
| 137 | + setSupportActionBar(toolbar); |
| 138 | + getSupportActionBar().setTitle(title); |
| 139 | + getSupportActionBar().setDisplayHomeAsUpEnabled(false); |
| 140 | + getSupportActionBar().setDisplayShowHomeEnabled(false); |
| 141 | + } |
| 142 | + |
| 143 | + public void github(View view) { |
| 144 | + AdsAdmob.showInterestialAd(this, null); |
| 145 | + this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/TimScriptov/Disassembler.git"))); |
| 146 | + } |
| 147 | + |
| 148 | + public void telegram(View view) { |
| 149 | + AdsAdmob.showInterestialAd(this, null); |
| 150 | + this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/dexprotect"))); |
| 151 | + } |
| 152 | + |
| 153 | + public void toNameDemangler(View view) { |
| 154 | + AdsAdmob.showInterestialAd(this, null); |
| 155 | + startActivity(new Intent(this, NameDemanglerActivity.class)); |
| 156 | + } |
| 157 | + |
| 158 | + public void symbols(View view) { |
| 159 | + AdsAdmob.showInterestialAd(this, runSymbols()); |
| 160 | + } |
| 161 | + |
| 162 | + public Function0<Unit> runSymbols() { |
| 163 | + AdsAdmob.showInterestialAd(this, null); |
| 164 | + Intent intent = new Intent(this, MainActivity.class); |
| 165 | + startActivity(intent); |
| 166 | + return null; |
| 167 | + } |
| 168 | + |
| 169 | + public void hexViewer(View view) { |
| 170 | + AdsAdmob.showInterestialAd(this, runHexViewer()); |
| 171 | + } |
| 172 | + |
| 173 | + public Function0<Unit> runHexViewer() { |
| 174 | + Intent intent = new Intent(this, fr.ralala.hexviewer.ui.activities.MainActivity.class); |
| 175 | + startActivity(intent); |
| 176 | + return null; |
| 177 | + } |
| 178 | + |
| 179 | + public void donate(View v) { |
| 180 | + iapConnector.purchase(this, "donate_disassembler"); |
| 181 | + } |
| 182 | + |
| 183 | + @TargetApi(Build.VERSION_CODES.M) |
| 184 | + @Override |
| 185 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 186 | + super.onActivityResult(requestCode, resultCode, data); |
| 187 | + if (requestCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) { |
| 188 | + if (!Settings.canDrawOverlays(this)) { |
| 189 | + checkPermission(); |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + public void checkPermission() { |
| 195 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 196 | + if (!Settings.canDrawOverlays(this)) { |
| 197 | + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, |
| 198 | + Uri.parse("package:" + getPackageName())); |
| 199 | + startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | +} |
0 commit comments