Skip to content

Commit

Permalink
Added Audio cutter
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhPatange committed Nov 30, 2019
1 parent 8aaafd4 commit 7bf0752
Show file tree
Hide file tree
Showing 18 changed files with 713 additions and 583 deletions.
Binary file modified .gradle/4.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.6/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.6/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/4.6/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
5 changes: 3 additions & 2 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

734 changes: 159 additions & 575 deletions .idea/workspace.xml

Large diffs are not rendered by default.

51 changes: 49 additions & 2 deletions app/src/main/java/com/kpstv/youtube/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.kpstv.youtube.fragments.PlaylistFragment;
import com.kpstv.youtube.fragments.SFragment;
import com.kpstv.youtube.fragments.SearchFragment;
import com.kpstv.youtube.fragments.SleepBottomSheet;
import com.kpstv.youtube.models.MetaModel;
import com.kpstv.youtube.models.NPlayModel;
import com.kpstv.youtube.models.YTConfig;
Expand All @@ -99,6 +100,7 @@
import org.json.JSONObject;

import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -117,7 +119,7 @@
import static com.facebook.network.connectionclass.ConnectionQuality.MODERATE;
import static com.facebook.network.connectionclass.ConnectionQuality.POOR;

public class MainActivity extends AppCompatActivity implements AppSettings, HistoryBottomSheet.BottomSheetListener, NCFragment.NoConnectionListener {
public class MainActivity extends AppCompatActivity implements AppSettings, SleepBottomSheet.ItemClickListener, HistoryBottomSheet.BottomSheetListener, NCFragment.NoConnectionListener {

// https://www.googleapis.com/youtube/v3/videos?id=BDocp-VpCwY&key=AIzaSyBYunDr6xBmBAgyQx7IW2qc770aoYBidLw&part=snippet,statistics

Expand Down Expand Up @@ -152,7 +154,7 @@ public class MainActivity extends AppCompatActivity implements AppSettings, Hist
public static DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
public static TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
public static TrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
private String TAG = "MainActivity";
private String TAG = "MainActivity"; public static String selectedItemText=""; public static int sleepSeconds;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -164,6 +166,16 @@ protected void onCreate(Bundle savedInstanceState) {
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();


/* if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}*/

dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this,
Util.getUserAgent(MainActivity.this,
getResources().getString(R.string.app_name)), BANDWIDTH_METER);
Expand Down Expand Up @@ -466,6 +478,39 @@ public void ReplaceFragment() {
} else Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show();
}

@Override
public void onItemClick(TextView view) {
selectedItemText = view.getText().toString();
switch (selectedItemText) {
case "5 minutes":
sleepSeconds = 5*60;
break;
case "10 minutes":
sleepSeconds = 10*60;
break;
case "15 minutes":
sleepSeconds = 15*60;
break;
case "30 minutes":
sleepSeconds = 30*60;
break;
case "45 minutes":
sleepSeconds = 45*60;
break;
case "60 minutes":
sleepSeconds = 60*60;
break;
case "End of track":
sleepSeconds = -2;
break;
case "None":
selectedItemText="";
sleepSeconds=0;
break;
}
libraryFrag.onActivityResult(100,0,null);
}

void openPlayer() {
Intent i=new Intent(MainActivity.this,PlayerActivity2.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Expand All @@ -477,6 +522,7 @@ void openPlayer() {
overridePendingTransition(R.anim.slide_up,R.anim.slide_down);
}


@SuppressLint("StaticFieldLeak")
boolean CheckIntent(Intent incoming) {
if (Intent.ACTION_SEND.equals(incoming.getAction())
Expand Down Expand Up @@ -621,6 +667,7 @@ protected Void doInBackground(Void... voids) {
public static ArrayList<String> yturls;
public static int ytIndex = 0;


static class loadVideo extends AsyncTask<String,String,Void> {

@SuppressLint("StaticFieldLeak")
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/kpstv/youtube/PlayerActivity2.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ void showListDialog() {
config.setAudioUrl(MainActivity.audioLink);
String filename;
if (config.getText().length() > 55) {
filename = config.getTitle().substring(0, 55) + "." + config.getExt();
filename = config.getTitle().substring(0, 55).trim() + "." + config.getExt();
} else {
filename = config.getChannelTitle() +" - " + config.getTitle() + "." + config.getExt();
filename = config.getChannelTitle().trim() +" - " + config.getTitle() + "." + config.getExt();
}
filename = filename.replaceAll("[\\\\><\"|*?%:#/]", "");
final String fileCurrent = filename; // Using this since current filename cannot be placed as final
Expand Down
81 changes: 79 additions & 2 deletions app/src/main/java/com/kpstv/youtube/fragments/LibraryFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@


import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
Expand All @@ -23,11 +30,14 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.hiteshsondhi88.libffmpeg.FileUtils;
import com.kpstv.youtube.AppSettings;
import com.kpstv.youtube.MainActivity;
import com.kpstv.youtube.R;
import com.kpstv.youtube.RingdroidEditActivity;
import com.kpstv.youtube.SettingsActivity;
import com.kpstv.youtube.adapters.SearchAdapter;
import com.kpstv.youtube.models.PlaylistModel;
Expand All @@ -38,19 +48,27 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.ArrayList;

import static android.app.Activity.RESULT_OK;

public class LibraryFragment extends Fragment implements AppSettings {

public LibraryFragment() {}

View v;
Toolbar toolbar; FragmentActivity activity;
LinearLayout playlistLayout, settingsLayout, favLayout,SOW,SOF;
ImageView githubView,pulseView,myWebView;
LinearLayout playlistLayout, settingsLayout, sleepLayout, audioCutterLayout, favLayout,SOW,SOF;
ImageView githubView,pulseView,myWebView,moonId;
RecyclerView recyclerView; LinearLayoutManager manager;
String region; LinearLayout commonLayout; RelativeLayout progressLayout; SearchAdapter adapter;
SharedPreferences preferences; ArrayList<SearchModel> models;
NestedScrollView nestedScrollView; boolean networkCheck=false;
TextView sleepTimerTextview;

private static final String TAG = "LibraryFragment";

Expand Down Expand Up @@ -89,7 +107,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

void getAllViews() {
moonId = v.findViewById(R.id.moonId);
sleepTimerTextview = v.findViewById(R.id.sleepTimer_textview);
commonLayout = v.findViewById(R.id.common_recycler_layout);
sleepLayout = v.findViewById(R.id.sleepTimer_layout);
audioCutterLayout = v.findViewById(R.id.audio_cutter_layout);
favLayout = v.findViewById(R.id.favourite_layout);
progressLayout = v.findViewById(R.id.progressLayout);
nestedScrollView = v.findViewById(R.id.nestedScrollView);
Expand Down Expand Up @@ -216,6 +238,7 @@ protected Void doInBackground(Void... voids) {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}


@Override
public void onResume() {
String newregion = preferences.getString("pref_select_region","global");
Expand All @@ -233,8 +256,61 @@ public void onResume() {
super.onResume();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1: // Request code for audio cutter
if (resultCode == RESULT_OK) {

Uri uri = data.getData();
String path = YTutils.getPath(activity,uri);
startEditor("file:/"+path);
}
break;
case 100: //Request code for sleep Timer
if (!MainActivity.selectedItemText.isEmpty()) {
moonId.setColorFilter(getResources().getColor(R.color.colorAccent));
sleepTimerTextview.setText("Sleep Timer - "+MainActivity.selectedItemText);
}else {
moonId.clearColorFilter();
sleepTimerTextview.setText("Sleep Timer");
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}


private void startEditor(String filePathUri) {
Intent intent = new Intent(activity, RingdroidEditActivity.class);
intent.putExtra("FILE_PATH", filePathUri);
startActivity(intent);
}

void preClicks() {


sleepLayout.setOnClickListener(view -> {
SleepBottomSheet bottomSheet = new SleepBottomSheet();
bottomSheet.show(activity.getSupportFragmentManager(),MainActivity.selectedItemText);
});

audioCutterLayout.setOnClickListener(view -> {

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("audio/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);

try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
1);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(activity, "No file manager installed", Toast.LENGTH_SHORT).show();
}
});

favLayout.setOnClickListener(view -> {

String data = YTutils.readContent(activity,"favourite.csv");
Expand Down Expand Up @@ -313,4 +389,5 @@ void preClicks() {
});
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.kpstv.youtube.fragments;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kpstv.youtube.R;

import org.w3c.dom.Text;

public class SleepBottomSheet extends BottomSheetDialogFragment {

ItemClickListener listener; Context context;
TextView mins5,mins10,mins15,mins30,mins45,mins60,eot,snone;
View v; LinearLayout linearLayout; Fragment parentFrag;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.sleep_bottom_sheet,container);
getAllViews();

context = getContext();

mins5.setOnClickListener(view -> click(mins5));
mins10.setOnClickListener(view -> click(mins10));
mins15.setOnClickListener(view -> click(mins15));
mins30.setOnClickListener(view -> click(mins30));
mins45.setOnClickListener(view -> click(mins45));
mins60.setOnClickListener(view -> click(mins60));
eot.setOnClickListener(view -> click(eot));
snone.setOnClickListener(view -> click(snone));

if (getTag()!=null && !getTag().isEmpty()) {
for (int i=0;i<linearLayout.getChildCount();i++) {
View v = linearLayout.getChildAt(i);
if (v instanceof TextView && ((TextView) v).getText().toString().equals(getTag())) {
((TextView) v).setTextColor(context.getResources().getColor(R.color.colorAccent));
snone.setVisibility(View.VISIBLE);
}
}
}

return v;
}

void click(TextView v) {
listener.onItemClick(v);
dismiss();
}

void getAllViews() {
linearLayout = v.findViewById(R.id.linearLayout);
mins5 = v.findViewById(R.id.s5mins);
snone = v.findViewById(R.id.snone);
mins10 = v.findViewById(R.id.s10mins);
mins15 = v.findViewById(R.id.s15mins);
mins30 = v.findViewById(R.id.s30mins);
mins45 = v.findViewById(R.id.s45mins);
mins60 = v.findViewById(R.id.s60mins);
eot = v.findViewById(R.id.eot);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);

try {
listener = (ItemClickListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement BottomSheetListener");
}
}

public interface ItemClickListener {
void onItemClick(TextView view);
}
}
Loading

0 comments on commit 7bf0752

Please sign in to comment.