added ability to share txt file to the app
txt file can have any links, playlist links or simple queries. The app will go through each line and put them in the result page
This commit is contained in:
parent
c855b6ad2e
commit
a699711671
6 changed files with 73 additions and 37 deletions
|
|
@ -94,7 +94,7 @@
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/filter_chip.xml" value="0.18854166666666666" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/filter_chip.xml" value="0.18854166666666666" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_downloads.xml" value="0.22" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_downloads.xml" value="0.22" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_history.xml" value="0.2" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_history.xml" value="0.2" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_home.xml" value="0.16" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_home.xml" value="0.25" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_more.xml" value="0.33" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_more.xml" value="0.33" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_music_editor.xml" value="0.16875" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_music_editor.xml" value="0.16875" />
|
||||||
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_settings.xml" value="0.16875" />
|
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/layout/fragment_settings.xml" value="0.16875" />
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<data android:mimeType="text/plain" />
|
<data android:mimeType="text/plain" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="application/txt" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".page.settings.SettingsActivity"
|
android:name=".page.settings.SettingsActivity"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -28,6 +29,12 @@ import com.deniscerri.ytdlnis.service.IDownloaderService;
|
||||||
import com.deniscerri.ytdlnis.util.NotificationUtil;
|
import com.deniscerri.ytdlnis.util.NotificationUtil;
|
||||||
import com.deniscerri.ytdlnis.util.UpdateUtil;
|
import com.deniscerri.ytdlnis.util.UpdateUtil;
|
||||||
|
|
||||||
|
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.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -150,14 +157,32 @@ public class MainActivity extends AppCompatActivity{
|
||||||
|
|
||||||
public void handleIntents(Intent intent){
|
public void handleIntents(Intent intent){
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if(Intent.ACTION_SEND.equals(action)){
|
String type = intent.getType();
|
||||||
|
if(Intent.ACTION_SEND.equals(action) && type != null){
|
||||||
Log.e(TAG, action);
|
Log.e(TAG, action);
|
||||||
|
|
||||||
homeFragment = new HomeFragment();
|
homeFragment = new HomeFragment();
|
||||||
downloadsFragment = new DownloadsFragment();
|
downloadsFragment = new DownloadsFragment();
|
||||||
moreFragment = new MoreFragment();
|
moreFragment = new MoreFragment();
|
||||||
|
if (type.equalsIgnoreCase("application/txt")){
|
||||||
homeFragment.handleIntent(intent);
|
try{
|
||||||
|
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
InputStream is = getContentResolver().openInputStream(uri);
|
||||||
|
StringBuilder textBuilder = new StringBuilder();
|
||||||
|
Reader reader = new BufferedReader(new InputStreamReader
|
||||||
|
(is, Charset.forName(StandardCharsets.UTF_8.name())));
|
||||||
|
int c = 0;
|
||||||
|
while ((c = reader.read()) != -1) {
|
||||||
|
textBuilder.append((char) c);
|
||||||
|
}
|
||||||
|
String[] lines = textBuilder.toString().split("\n");
|
||||||
|
homeFragment.handleFileIntent(lines);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
homeFragment.handleIntent(intent);
|
||||||
|
}
|
||||||
initFragments();
|
initFragments();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.media.MediaScannerConnection;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
@ -20,15 +19,13 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.deniscerri.ytdlnis.MainActivity;
|
import com.deniscerri.ytdlnis.MainActivity;
|
||||||
|
|
@ -48,18 +45,8 @@ import com.google.android.material.chip.Chip;
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
import java.io.File;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
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;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
@ -69,6 +56,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
private View fragmentView;
|
private View fragmentView;
|
||||||
private LinearProgressIndicator progressBar;
|
private LinearProgressIndicator progressBar;
|
||||||
private String inputQuery;
|
private String inputQuery;
|
||||||
|
private String[] inputQueries;
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private HomeRecyclerViewAdapter homeRecyclerViewAdapter;
|
private HomeRecyclerViewAdapter homeRecyclerViewAdapter;
|
||||||
private ShimmerFrameLayout shimmerCards;
|
private ShimmerFrameLayout shimmerCards;
|
||||||
|
|
@ -238,13 +226,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
|
|
||||||
initMenu();
|
initMenu();
|
||||||
|
|
||||||
if (inputQuery != null) {
|
|
||||||
parseQuery();
|
|
||||||
inputQuery = null;
|
|
||||||
} else {
|
|
||||||
initCards();
|
|
||||||
}
|
|
||||||
|
|
||||||
homeFabs = fragmentView.findViewById(R.id.home_fabs);
|
homeFabs = fragmentView.findViewById(R.id.home_fabs);
|
||||||
downloadFabs = homeFabs.findViewById(R.id.download_selected_coordinator);
|
downloadFabs = homeFabs.findViewById(R.id.download_selected_coordinator);
|
||||||
downloadAllFab = homeFabs.findViewById(R.id.download_all_coordinator);
|
downloadAllFab = homeFabs.findViewById(R.id.download_all_coordinator);
|
||||||
|
|
@ -262,6 +243,22 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
download_all_fab.setTag("downloadAll");
|
download_all_fab.setTag("downloadAll");
|
||||||
download_all_fab.setOnClickListener(this);
|
download_all_fab.setOnClickListener(this);
|
||||||
|
|
||||||
|
if (inputQueries != null) {
|
||||||
|
dbManager = new DBManager(context);
|
||||||
|
dbManager.clearResults();
|
||||||
|
dbManager.close();
|
||||||
|
for (int i = 0; i < inputQueries.length; i++){
|
||||||
|
inputQuery = inputQueries[i];
|
||||||
|
activity.runOnUiThread(() -> parseQuery(true));
|
||||||
|
}
|
||||||
|
if (inputQueries.length > 1){
|
||||||
|
Toast.makeText(context, getString(R.string.finished_loading), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
inputQueries = null;
|
||||||
|
} else {
|
||||||
|
initCards();
|
||||||
|
}
|
||||||
|
|
||||||
return fragmentView;
|
return fragmentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -361,7 +358,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
downloadFabs.setVisibility(View.GONE);
|
downloadFabs.setVisibility(View.GONE);
|
||||||
selectedObjects = new ArrayList<>();
|
selectedObjects = new ArrayList<>();
|
||||||
inputQuery = query.trim();
|
inputQuery = query.trim();
|
||||||
parseQuery();
|
parseQuery(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,7 +397,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
|
|
||||||
|
|
||||||
public void handleIntent(Intent intent) {
|
public void handleIntent(Intent intent) {
|
||||||
inputQuery = intent.getStringExtra(Intent.EXTRA_TEXT);
|
inputQueries = new String[]{intent.getStringExtra(Intent.EXTRA_TEXT)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleFileIntent(String[] lines) {
|
||||||
|
inputQueries = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToTop() {
|
public void scrollToTop() {
|
||||||
|
|
@ -408,7 +409,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
new Handler(Looper.getMainLooper()).post(() -> ((AppBarLayout) topAppBar.getParent()).setExpanded(true, true));
|
new Handler(Looper.getMainLooper()).post(() -> ((AppBarLayout) topAppBar.getParent()).setExpanded(true, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseQuery() {
|
private void parseQuery(boolean resetResults) {
|
||||||
shimmerCards.startShimmer();
|
shimmerCards.startShimmer();
|
||||||
shimmerCards.setVisibility(View.VISIBLE);
|
shimmerCards.setVisibility(View.VISIBLE);
|
||||||
homeRecyclerViewAdapter.clear();
|
homeRecyclerViewAdapter.clear();
|
||||||
|
|
@ -444,11 +445,12 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
resultObjects = infoUtil.search(query);
|
if (resetResults) resultObjects.clear();
|
||||||
|
resultObjects.addAll(infoUtil.search(query));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, e.toString());
|
Log.e(TAG, e.toString());
|
||||||
}
|
}
|
||||||
dbManager.clearResults();
|
if (resetResults) dbManager.clearResults();
|
||||||
dbManager.addToResults(resultObjects);
|
dbManager.addToResults(resultObjects);
|
||||||
dbManager.close();
|
dbManager.close();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> {
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
|
|
@ -484,13 +486,13 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
resultObjects.clear();
|
if (resetResults) resultObjects.clear();
|
||||||
resultObjects.add(infoUtil.getVideo(query));
|
resultObjects.add(infoUtil.getVideo(query));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, e.toString());
|
Log.e(TAG, e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
dbManager.clearResults();
|
if (resetResults) dbManager.clearResults();
|
||||||
dbManager.addToResults(resultObjects);
|
dbManager.addToResults(resultObjects);
|
||||||
dbManager.close();
|
dbManager.close();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> {
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
|
|
@ -516,10 +518,12 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String nextPageToken = "";
|
String nextPageToken = "";
|
||||||
dbManager.clearResults();
|
if (resetResults) dbManager.clearResults();
|
||||||
dbManager.close();
|
dbManager.close();
|
||||||
resultObjects.clear();
|
if (resetResults){
|
||||||
homeRecyclerViewAdapter.setVideoList(new ArrayList<>(), true);
|
resultObjects.clear();
|
||||||
|
homeRecyclerViewAdapter.setVideoList(new ArrayList<>(), true);
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
InfoUtil.PlaylistTuple tmp = infoUtil.getPlaylist(query, nextPageToken);
|
InfoUtil.PlaylistTuple tmp = infoUtil.getPlaylist(query, nextPageToken);
|
||||||
ArrayList<Video> tmp_vids = tmp.getVideos();
|
ArrayList<Video> tmp_vids = tmp.getVideos();
|
||||||
|
|
@ -561,11 +565,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
resultObjects.clear();
|
if (resetResults) resultObjects.clear();
|
||||||
ArrayList<Video> video = infoUtil.getFromYTDL(query);
|
ArrayList<Video> video = infoUtil.getFromYTDL(query);
|
||||||
if (video != null) {
|
if (video != null) {
|
||||||
resultObjects.addAll(video);
|
resultObjects.addAll(video);
|
||||||
dbManager.clearResults();
|
if (resetResults) dbManager.clearResults();
|
||||||
dbManager.addToResults(resultObjects);
|
dbManager.addToResults(resultObjects);
|
||||||
dbManager.close();
|
dbManager.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,4 +129,5 @@
|
||||||
<string name="delete_selected">Fshi të zgjedhurat</string>
|
<string name="delete_selected">Fshi të zgjedhurat</string>
|
||||||
<string name="you_are_going_to_delete_multiple_items">Je duke fshirë disa elementë</string>
|
<string name="you_are_going_to_delete_multiple_items">Je duke fshirë disa elementë</string>
|
||||||
<string name="delete_files_too">Fshi skedarët nga sistemi</string>
|
<string name="delete_files_too">Fshi skedarët nga sistemi</string>
|
||||||
|
<string name="finished_loading">U ngarkuan të gjitha!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -134,4 +134,5 @@
|
||||||
<string name="delete_selected">Delete Selected</string>
|
<string name="delete_selected">Delete Selected</string>
|
||||||
<string name="you_are_going_to_delete_multiple_items">You are going to delete multiple items</string>
|
<string name="you_are_going_to_delete_multiple_items">You are going to delete multiple items</string>
|
||||||
<string name="delete_files_too">Delete the files from the system</string>
|
<string name="delete_files_too">Delete the files from the system</string>
|
||||||
|
<string name="finished_loading">Finished Loading!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue