Skip to content

Commit

Permalink
breadcrumbs #2
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscerri committed Dec 26, 2022
1 parent 2af2148 commit d772e54
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 24 deletions.
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppDefaultTheme" >
<activity android:name=".MainActivity" >
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -35,7 +36,8 @@
</activity>
<activity
android:name=".page.settings.SettingsActivity"
android:parentActivityName=".MainActivity" >
android:parentActivityName=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="ytdlnis.settings.SettingsActivity" />
<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -44,7 +46,8 @@
<activity
android:name=".page.CustomCommandActivity"
android:theme="@style/AppDefaultTheme"
android:parentActivityName=".MainActivity">
android:parentActivityName=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="ytdlnis.page.CustomCommandActivity" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/deniscerri/ytdlnis/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import android.app.Application;
import android.util.Log;
import android.widget.Toast;

import androidx.preference.PreferenceManager;

import com.deniscerri.ytdlnis.util.NotificationUtil;
import com.google.android.material.color.DynamicColors;
import com.yausername.aria2c.Aria2c;
import com.yausername.ffmpeg.FFmpeg;
import com.yausername.youtubedl_android.YoutubeDL;
import com.yausername.youtubedl_android.YoutubeDLException;

import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.exceptions.UndeliverableException;
Expand Down
63 changes: 52 additions & 11 deletions app/src/main/java/com/deniscerri/ytdlnis/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.deniscerri.ytdlnis;

import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

Expand All @@ -26,25 +29,18 @@
import com.deniscerri.ytdlnis.page.settings.SettingsActivity;
import com.deniscerri.ytdlnis.service.IDownloaderListener;
import com.deniscerri.ytdlnis.service.IDownloaderService;
import com.deniscerri.ytdlnis.util.NotificationUtil;
import com.deniscerri.ytdlnis.util.UpdateUtil;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;


public class MainActivity extends AppCompatActivity{

Expand All @@ -65,7 +61,7 @@ public class MainActivity extends AppCompatActivity{
private ArrayList<IDownloaderListener> listeners = null;
private IDownloaderService iDownloaderService;

private final ServiceConnection serviceConnection = new ServiceConnection() {
public final ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
downloaderService = ((DownloaderService.LocalBinder) service).getService();
Expand Down Expand Up @@ -137,6 +133,9 @@ protected void onCreate(Bundle savedInstanceState) {
}
return true;
});

askPermissions();

Intent intent = getIntent();
handleIntents(intent);
}
Expand Down Expand Up @@ -303,4 +302,46 @@ private void checkUpdate(){
}
}


private void askPermissions(){
if(!checkFilePermission()){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.e(TAG, String.valueOf(grantResults[0]));
for(int i = 0; i < permissions.length; i++){
if(grantResults[i] == PackageManager.PERMISSION_DENIED){
createPermissionRequestDialog();
}
}
}

private void exit(){
this.finishAffinity();
System.exit(0);
}

private boolean checkFilePermission(){
return ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
}

private void createPermissionRequestDialog(){
MaterialAlertDialogBuilder dialog = new MaterialAlertDialogBuilder(this);
dialog.setTitle(getString(R.string.warning));
dialog.setMessage(getString(R.string.request_permission_desc));
dialog.setOnCancelListener(dialogInterface -> exit());
dialog.setNegativeButton(getString(R.string.exit_app), (dialogInterface, i) -> exit());
dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null));
startActivity(intent);
System.exit(0);
});
dialog.show();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.IBinder;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
Expand Down Expand Up @@ -75,8 +76,9 @@ public void onDownloadStart(DownloadInfo info) {
}

public void onDownloadProgress(DownloadInfo info) {
output.append("\n" + info.getOutputLine());
scrollView.scrollTo(0, scrollView.getMaxScrollAmount());
output.append("\n" + info.getOutputLine() + "\n");
output.scrollTo(0, output.getHeight());
scrollView.fullScroll(View.FOCUS_DOWN);
}

public void onDownloadError(DownloadInfo info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import android.content.ServiceConnection;
import android.os.IBinder;
import com.deniscerri.ytdlnis.DownloaderService;
import com.deniscerri.ytdlnis.MainActivity;
import com.deniscerri.ytdlnis.service.IDownloaderListener;
import com.deniscerri.ytdlnis.service.IDownloaderService;
import com.deniscerri.ytdlnis.util.NotificationUtil;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Notification createDownloadServiceNotification(PendingIntent pendingInten
.setContentIntent(pendingIntent)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
.clearActions()
.addAction(0, context.getString(R.string.cancel), cancelNotificationPendingIntent)
//.addAction(0, context.getString(R.string.cancel), cancelNotificationPendingIntent)
.build();

return notification;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_custom_command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ScrollView
android:id="@+id/custom_command_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="150dp"
>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,7 @@
<string name="delete_file_too">Delete the file from the device</string>
<string name="delete_files_too">Delete the files from the device</string>
<string name="finished_loading">Loaded.</string>
<string name="request_permission_desc">This app needs File Permissions to save downloads on the device</string>
<string name="exit_app">Exit App</string>
<string name="warning">Warning</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

def versionMajor = 1
def versionMinor = 4
def versionPatch = 2
def versionPatch = 3
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

ext {
Expand Down

0 comments on commit d772e54

Please sign in to comment.