mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-26 08:37:29 +00:00
remove direct download function
This commit is contained in:
parent
3cc5040110
commit
af4aaf6e2a
@ -77,33 +77,6 @@
|
||||
android:screenOrientation="portrait"
|
||||
android:taskAffinity="awais.instagrabber.errorreport"
|
||||
android:theme="@android:style/Theme.DeviceDefault.Dialog" />
|
||||
<activity
|
||||
android:name=".activities.DirectDownload"
|
||||
android:allowEmbedded="false"
|
||||
android:allowTaskReparenting="false"
|
||||
android:autoRemoveFromRecents="true"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:description="@string/direct_download_desc"
|
||||
android:documentLaunchMode="never"
|
||||
android:excludeFromRecents="true"
|
||||
android:finishOnTaskLaunch="true"
|
||||
android:label="@string/direct_download"
|
||||
android:launchMode="singleTask"
|
||||
android:lockTaskMode="never"
|
||||
android:noHistory="false"
|
||||
android:theme="@style/Theme.AppCompat.Translucent">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
<action android:name="android.intent.action.WEB_SEARCH" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.Login"
|
||||
android:label="@string/login"
|
||||
|
@ -1,152 +0,0 @@
|
||||
package awais.instagrabber.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Notification;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.asyncs.PostFetcher;
|
||||
import awais.instagrabber.interfaces.FetchListener;
|
||||
import awais.instagrabber.models.IntentModel;
|
||||
import awais.instagrabber.models.enums.IntentModelType;
|
||||
import awais.instagrabber.repositories.responses.Media;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.CookieUtils;
|
||||
import awais.instagrabber.utils.DownloadUtils;
|
||||
import awais.instagrabber.utils.IntentUtils;
|
||||
import awais.instagrabber.utils.TextUtils;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
|
||||
public final class DirectDownload extends AppCompatActivity {
|
||||
private static final int NOTIFICATION_ID = 1900000000;
|
||||
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
|
||||
|
||||
private boolean contextFound = false;
|
||||
private Intent intent;
|
||||
private Context context;
|
||||
private NotificationManagerCompat notificationManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_direct);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowAttributesChanged(final WindowManager.LayoutParams params) {
|
||||
super.onWindowAttributesChanged(params);
|
||||
if (!contextFound) {
|
||||
intent = getIntent();
|
||||
context = getApplicationContext();
|
||||
if (intent != null && context != null) {
|
||||
contextFound = true;
|
||||
checkPermissions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
if (!contextFound) {
|
||||
intent = getIntent();
|
||||
context = getApplicationContext();
|
||||
if (intent != null && context != null) {
|
||||
contextFound = true;
|
||||
checkPermissions();
|
||||
}
|
||||
}
|
||||
return super.getResources();
|
||||
}
|
||||
|
||||
private synchronized void checkPermissions() {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
doDownload();
|
||||
return;
|
||||
}
|
||||
ActivityCompat.requestPermissions(this, DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
|
||||
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
|
||||
doDownload();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void doDownload() {
|
||||
CookieUtils.setupCookies(Utils.settingsHelper.getString(Constants.COOKIE));
|
||||
notificationManager = NotificationManagerCompat.from(getApplicationContext());
|
||||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action) || Intent.ACTION_MAIN.equals(action)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
boolean error = true;
|
||||
|
||||
String data = null;
|
||||
final Bundle extras = intent.getExtras();
|
||||
if (extras != null) {
|
||||
final Object extraData = extras.get(Intent.EXTRA_TEXT);
|
||||
if (extraData != null) {
|
||||
error = false;
|
||||
data = extraData.toString();
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
final Uri intentData = intent.getData();
|
||||
if (intentData != null) data = intentData.toString();
|
||||
}
|
||||
if (data == null || TextUtils.isEmpty(data)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
final IntentModel model = IntentUtils.parseUrl(data);
|
||||
if (model == null || model.getType() != IntentModelType.POST) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
final String text = model.getText();
|
||||
new PostFetcher(text, new FetchListener<Media>() {
|
||||
@Override
|
||||
public void doBefore() {
|
||||
if (notificationManager == null) return;
|
||||
final Notification fetchingPostNotification = new NotificationCompat.Builder(getApplicationContext(), Constants.DOWNLOAD_CHANNEL_ID)
|
||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||
.setSmallIcon(R.drawable.ic_download)
|
||||
.setAutoCancel(false)
|
||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||
.setContentText(getString(R.string.direct_download_loading))
|
||||
.build();
|
||||
notificationManager.notify(NOTIFICATION_ID, fetchingPostNotification);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final Media result) {
|
||||
if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID);
|
||||
if (result == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
DownloadUtils.download(getApplicationContext(), result);
|
||||
finish();
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
Loading…
Reference in New Issue
Block a user