Skip to content

Commit

Permalink
FullSize Fix save
Browse files Browse the repository at this point in the history
  • Loading branch information
mkikets99 committed Nov 10, 2020
1 parent 0634cb7 commit e8a7ee6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
93 changes: 83 additions & 10 deletions app/src/main/java/ua/sim23/tsd/blocker/InfoLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ua.sim23.tsd.blocker;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
Expand All @@ -8,20 +9,51 @@

import androidx.annotation.RequiresApi;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class InfoLoader {
private static Set<String> checkedApps;
private static SharedPreferences sp;
private static List<String> checkedApps;
//private static SharedPreferences sp;
private static Activity a;
private static String Password;

@RequiresApi(api = Build.VERSION_CODES.M)
public static void Load(MainActivity activity){
sp = activity.getSharedPreferences(activity.getPackageName() , Context.MODE_PRIVATE);
checkedApps = sp.getStringSet("saved apps",new ArraySet<String>());
Password = sp.getString("password",null);

//sp = activity.getSharedPreferences(activity.getPackageName() , Context.MODE_PRIVATE);
a = activity;
try {
String Apps = FileRead("savedapps");
checkedApps = Arrays.asList(Apps.split("\\r?\\n"));
if(checkedApps==null) checkedApps = new ArrayList<String>();
Password = FileRead("password");
}catch(Exception e){
e.printStackTrace();
checkedApps = new ArrayList<String>();
}
}
private static void FileWrite(String file, String data) throws IOException {
FileOutputStream fileOutputStream = a.openFileOutput(file, Context.MODE_PRIVATE);
fileOutputStream.write(data.getBytes());
fileOutputStream.close();
}
private static String FileRead(String file) throws IOException {
FileInputStream fileInputStream = a.openFileInput(file);
int read = -1;
StringBuffer buffer = new StringBuffer();
while((read =fileInputStream.read())!= -1){
buffer.append((char)read);
}
return buffer.toString();
}
public static boolean passwordChack(String pass){
return Password.equals(pass);
Expand All @@ -31,22 +63,63 @@ public static boolean isPassSet(){
}
public static void setPassword(String password){
Password = password;
sp.edit().putString("password",Password).apply();
try {
FileWrite("password",password);
}catch(Exception e){
e.printStackTrace();
}
//sp.edit().putString("password",Password).apply();
}

public static void addAppToList(String pack){
checkedApps.add(pack);
sp.edit().putStringSet("saved apps",checkedApps).apply();
try {
String delim = "\n";

StringBuilder sb = new StringBuilder();

int i = 0;
while (i < checkedApps.size() - 1) {
sb.append(checkedApps.get(i));
sb.append(delim);
i++;
}
sb.append(checkedApps.get(i));

String res = sb.toString();
FileWrite("savedapps",res);
}catch(Exception e){
e.printStackTrace();
}
//sp.edit().putStringSet("saved apps",checkedApps).apply();
}
public static void delAppToList(String pack){
checkedApps.remove(pack);
sp.edit().putStringSet("saved apps",checkedApps).apply();
try {
String delim = "|";

StringBuilder sb = new StringBuilder();

int i = 0;
while (i < checkedApps.size() - 1) {
sb.append(checkedApps.get(i));
sb.append(delim);
i++;
}
sb.append(checkedApps.get(i));

String res = sb.toString();
FileWrite("savedapps",res);
}catch(Exception e){
e.printStackTrace();
}
//sp.edit().putStringSet("saved apps",checkedApps).apply();
}

public static boolean isIncheckedApps(String packname){
return checkedApps.contains(packname);
}
public static Set<String> getCheckedApps() {
public static List<String> getCheckedApps() {
return checkedApps;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/ua/sim23/tsd/blocker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void loadApps() {

Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
Set<String> appList = InfoLoader.getCheckedApps();
List<String> appList = InfoLoader.getCheckedApps();
//List<ApplicationInfo> availableApps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (String app : appList) {
AppInfo appinfo = new AppInfo();
Expand Down
Binary file modified builds/app-debug.apk
Binary file not shown.

0 comments on commit e8a7ee6

Please sign in to comment.