Skip to content

Commit

Permalink
Merge pull request #66 from swakwork/dev
Browse files Browse the repository at this point in the history
feat(Twitter): Added `Custom downloader`
  • Loading branch information
crimera authored Jul 6, 2024
2 parents 1e58d42 + 5ad7114 commit 1ae07fe
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/app/revanced/integrations/twitter/Pref.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class Pref {
public static boolean isRoundOffNumbersEnabled() {
return Utils.getBooleanPerf(Settings.MISC_ROUND_OFF_NUMBERS);
}

public static boolean isChirpFontEnabled() {
return Utils.getBooleanPerf(Settings.MISC_FONT);
}

public static boolean unShortUrl() {
return Utils.getBooleanPerf(Settings.TIMELINE_UNSHORT_URL);
}
Expand Down
40 changes: 36 additions & 4 deletions app/src/main/java/app/revanced/integrations/twitter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import android.content.Context;
import android.content.Intent;
import android.widget.LinearLayout;
import app.revanced.integrations.shared.settings.Setting;
import app.revanced.integrations.shared.settings.StringSetting;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.shared.settings.preference.SharedPrefCategory;
import app.revanced.integrations.twitter.settings.Settings;
import app.revanced.integrations.twitter.settings.BackupPrefFragment;
Expand All @@ -16,6 +17,13 @@
import org.json.JSONObject;
import java.util.*;
import com.google.android.material.tabs.TabLayout$g;
import android.app.DownloadManager;
import android.net.Uri;
import android.os.Build;
import app.revanced.integrations.twitter.Pref;
import android.os.Environment;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;

@SuppressWarnings("unused")
public class Utils {
Expand Down Expand Up @@ -102,7 +110,7 @@ public static Boolean setStringPref(String key,String val) {
return false;
}

public static String getStringPref(Setting<String> setting) {
public static String getStringPref(StringSetting setting) {
String value = sp.getString(setting.key, setting.defaultValue);
if (value.isBlank()) {
return setting.defaultValue;
Expand Down Expand Up @@ -161,7 +169,7 @@ public static void deleteSharedPrefAB(Context context,boolean flag) {
dialog.show();
}

public static Boolean getBooleanPerf(Setting<Boolean> setting) {
public static Boolean getBooleanPerf(BooleanSetting setting) {
return sp.getBoolean(setting.key, setting.defaultValue);
}
public static String getAll(boolean no_flags){
Expand Down Expand Up @@ -220,13 +228,37 @@ public static boolean setAll(String jsonString){
return sts;
}


public static String[] addPref(String[] prefs, String pref) {
String[] bigger = Arrays.copyOf(prefs, prefs.length+1);
bigger[prefs.length] = pref;
return bigger;
}

public static void downloadFile(String url, String filename) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading " + filename);
request.setTitle(filename);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Pref.getPublicFolder(), Pref.getVideoFolder(filename));
DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
long downloadId = manager.enqueue(request);
ctx.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (id == downloadId) {
toast(strRes("exo_download_completed")+": "+filename);
ctx.unregisterReceiver(this);
}
}
}, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

}

public static void toast(String msg){
app.revanced.integrations.shared.Utils.showToastShort(msg);
}
Expand Down
Loading

0 comments on commit 1ae07fe

Please sign in to comment.