Skip to content

Commit

Permalink
Enable minification
Browse files Browse the repository at this point in the history
  • Loading branch information
MuntashirAkon committed Jan 31, 2023
1 parent 79ef379 commit 376abc1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ android {

buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
Expand All @@ -66,7 +66,6 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package io.github.muntashirakon.setedit;

import android.Manifest;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextUtils;
import android.view.Menu;
Expand All @@ -20,13 +16,11 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -35,8 +29,6 @@

import org.json.JSONException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -64,9 +56,6 @@ public class EditorActivity extends AppCompatActivity implements AdapterView.OnI
private RecyclerView listView;
private SharedPreferences preferences;

private final ActivityResultLauncher<String> pre21StoragePermissionLauncher = registerForActivityResult(
new ActivityResultContracts.RequestPermission(), granted -> saveAsJsonLegacy());
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private final ActivityResultLauncher<String> post21SaveLauncher = registerForActivityResult(
new ActivityResultContracts.CreateDocument(),
uri -> {
Expand Down Expand Up @@ -166,9 +155,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_export) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
post21SaveLauncher.launch(getFileName());
} else saveAsJsonLegacy();
post21SaveLauncher.launch(getFileName());
return true;
} else if (id == R.id.action_theme) {
List<Integer> themeMap = new ArrayList<>(4);
Expand Down Expand Up @@ -240,23 +227,6 @@ private String getFileName() {
return "SetEdit-" + System.currentTimeMillis() + ".json";
}

private void saveAsJsonLegacy() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
pre21StoragePermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
return;
}
@SuppressWarnings("deprecation")
File file = new File(Environment.getExternalStorageDirectory(), getFileName());
try (OutputStream os = new FileOutputStream(file)) {
saveAsJson(os);
Toast.makeText(this, getString(R.string.saved_to_file, file.getAbsolutePath()), Toast.LENGTH_LONG).show();
} catch (Throwable th) {
th.printStackTrace();
Toast.makeText(this, R.string.failed, Toast.LENGTH_SHORT).show();
}
}

private void saveAsJson(OutputStream os) throws JSONException, IOException {
String jsonString = EditorUtils.getJson(adapter.getAllItems(), adapter instanceof SettingsRecyclerAdapter ?
((SettingsRecyclerAdapter) adapter).getSettingsType() : null);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/io/github/muntashirakon/setedit/Native.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.muntashirakon.setedit;

import android.os.Build;

import androidx.annotation.Keep;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -42,8 +45,10 @@ public static void setPropertyList(List<String[]> list) {
}
}

@Keep
public static native void readAndroidPropertiesPost26(PropertyCallback propertyCallback);

@Keep
public static native boolean readAndroidPropertyPre26(int n, String[] property);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.github.muntashirakon.setedit;

import androidx.annotation.Keep;

@Keep
public interface PropertyCallback {
void handleProperty(String key, String value);
}

0 comments on commit 376abc1

Please sign in to comment.