diff --git a/.idea/misc.xml b/.idea/misc.xml index 31af1e3..4847e21 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -56,13 +56,13 @@ - + - + - + @@ -72,7 +72,7 @@ - + diff --git a/app/src/main/java/com/theflexproject/thunder/adapter/IndexAdapter.java b/app/src/main/java/com/theflexproject/thunder/adapter/IndexAdapter.java index 9efa01d..dc9c1e9 100644 --- a/app/src/main/java/com/theflexproject/thunder/adapter/IndexAdapter.java +++ b/app/src/main/java/com/theflexproject/thunder/adapter/IndexAdapter.java @@ -1,5 +1,9 @@ package com.theflexproject.thunder.adapter; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestGDIndex; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestGoIndex; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestMapleIndex; + import android.content.Context; import android.os.Build; import android.view.LayoutInflater; @@ -13,10 +17,11 @@ import androidx.recyclerview.widget.RecyclerView; import com.theflexproject.thunder.R; -import com.theflexproject.thunder.utils.SendPostRequest; import com.theflexproject.thunder.database.DatabaseClient; import com.theflexproject.thunder.model.IndexLink; +import org.json.JSONException; + import java.io.IOException; import java.util.List; @@ -26,7 +31,6 @@ public class IndexAdapter extends RecyclerView.Adapter indexLinkList; - public IndexAdapter(Context mCtx, List indexLinkList) { this.mCtx = mCtx; this.indexLinkList = indexLinkList; @@ -45,6 +49,8 @@ public void onBindViewHolder(IndexViewHolder holder, int position) { holder.textViewUsername.setText(t.getUsername()); holder.textViewPassword.setText(t.getPassword()); + + if(t.getUsername().length()>0 && t.getPassword().length()>0){ holder.textViewUsername.setVisibility(View.VISIBLE); holder.textViewPassword.setVisibility(View.VISIBLE); @@ -101,16 +107,23 @@ void refreshIndexMovies(){ @RequiresApi(api = Build.VERSION_CODES.O) @Override public void run() { - SendPostRequest snd = new SendPostRequest(); try { DatabaseClient.getInstance(null).getAppDatabase().fileDao().deleteAllFromthisIndex(textViewLink.getText().toString()); - if(textViewUsername.getText().toString().length()<1 && textViewUsername.toString().length()<1){ - snd.postRequest(textViewLink.getText().toString()); - } - else { - snd.postRequest(textViewLink.getText().toString(),textViewUsername.getText().toString(), textViewPassword.getText().toString()); + String link = textViewLink.getText().toString(); + IndexLink indexLink =DatabaseClient.getInstance(null).getAppDatabase().indexLinksDao().find(link); + switch (indexLink.getType()) { + case "GDIndex": + postRequestGDIndex(textViewLink.getText().toString(), textViewUsername.getText().toString(), textViewPassword.getText().toString()); + break; + case "GoIndex": + postRequestGoIndex(textViewLink.getText().toString(), textViewUsername.getText().toString(), textViewPassword.getText().toString()); + + break; + case "MapleIndex": + postRequestMapleIndex(textViewLink.getText().toString(), textViewUsername.getText().toString(), textViewPassword.getText().toString()); + break; } - } catch (IOException e) { + } catch (IOException | JSONException e) { e.printStackTrace(); } } diff --git a/app/src/main/java/com/theflexproject/thunder/adapter/MovieRecyclerAdapterLibrary.java b/app/src/main/java/com/theflexproject/thunder/adapter/MovieRecyclerAdapterLibrary.java index 93b1376..c6ee09a 100644 --- a/app/src/main/java/com/theflexproject/thunder/adapter/MovieRecyclerAdapterLibrary.java +++ b/app/src/main/java/com/theflexproject/thunder/adapter/MovieRecyclerAdapterLibrary.java @@ -15,10 +15,10 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; +import com.theflexproject.thunder.Constants; import com.theflexproject.thunder.R; import com.theflexproject.thunder.model.File; import com.theflexproject.thunder.utils.sizetoReadablesize; -import com.theflexproject.thunder.Constants; import java.util.List; diff --git a/app/src/main/java/com/theflexproject/thunder/database/AppDatabase.java b/app/src/main/java/com/theflexproject/thunder/database/AppDatabase.java index 63a7c1b..8bb24e5 100644 --- a/app/src/main/java/com/theflexproject/thunder/database/AppDatabase.java +++ b/app/src/main/java/com/theflexproject/thunder/database/AppDatabase.java @@ -8,7 +8,7 @@ import com.theflexproject.thunder.model.IndexLink; import com.theflexproject.thunder.model.ResFormat; -@Database(entities = {ResFormat.class, File.class, IndexLink.class}, version = 10) +@Database(entities = {ResFormat.class, File.class, IndexLink.class}, version = 14) @TypeConverters({Converters.class}) public abstract class AppDatabase extends RoomDatabase { diff --git a/app/src/main/java/com/theflexproject/thunder/database/FileDao.java b/app/src/main/java/com/theflexproject/thunder/database/FileDao.java index aad7179..e1af48b 100644 --- a/app/src/main/java/com/theflexproject/thunder/database/FileDao.java +++ b/app/src/main/java/com/theflexproject/thunder/database/FileDao.java @@ -14,11 +14,8 @@ public interface FileDao { @Query("SELECT * FROM File") List getAll(); - @Query("SELECT * FROM file WHERE title LIKE :name") - File getbyName(String name); - - @Query("SELECT * FROM file WHERE name LIKE '%' || :fileName || '%'") - List getSearchQuery(String fileName); + @Query("SELECT * FROM file WHERE name LIKE '%' || :string || '%' OR title like '%' || :string || '%' OR urlString like '%' || :string || '%' or overview like '%' || :string || '%'") + List getSearchQuery(String string); @Query("SELECT * FROM file WHERE name LIKE :fileName") File getByFileName(String fileName); diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/AddNewIndexFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/AddNewIndexFragment.java index 8d47b1b..31ddb02 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/AddNewIndexFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/AddNewIndexFragment.java @@ -1,5 +1,9 @@ package com.theflexproject.thunder.fragments; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestGDIndex; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestGoIndex; +import static com.theflexproject.thunder.utils.SendPostRequest.postRequestMapleIndex; + import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; @@ -7,23 +11,25 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; -import androidx.fragment.app.Fragment; import com.theflexproject.thunder.MainActivity; import com.theflexproject.thunder.R; import com.theflexproject.thunder.database.DatabaseClient; import com.theflexproject.thunder.model.IndexLink; -import com.theflexproject.thunder.utils.SendPostRequest; + +import org.json.JSONException; import java.io.IOException; -public class AddNewIndexFragment extends Fragment { +public class AddNewIndexFragment extends BaseFragment { public static final String TAG = "ActionBottomDialog"; private EditText indexLinkView; @@ -32,6 +38,8 @@ public class AddNewIndexFragment extends Fragment { private Button save; private TextView refreshSuggest; + private RadioGroup radioIndexTypeGroup; + private RadioButton radioIndexTypeButton; public static AddNewIndexFragment newInstance(){ return new AddNewIndexFragment(); @@ -46,9 +54,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_add_index, container, false); - - return view; + return inflater.inflate(R.layout.fragment_add_index, container, false); } @@ -60,6 +66,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat save = view.findViewById(R.id.save); refreshSuggest = view.findViewById(R.id.suggestRefresh); + radioIndexTypeGroup=(RadioGroup)mActivity.findViewById(R.id.rb_group); + + @@ -71,18 +80,34 @@ public void onClick(View v) { indexLink.setLink(indexLinkView.getText().toString()); indexLink.setUsername(userNameView.getText().toString()); indexLink.setPassword(passWordView.getText().toString()); - if(indexLink.getUsername().length()<1 && indexLink.getPassword().length()<1){ - userNameView.setVisibility(View.GONE); - passWordView.setVisibility(View.GONE); - } + + int selectedId=radioIndexTypeGroup.getCheckedRadioButtonId(); + radioIndexTypeButton= mActivity.findViewById(selectedId); + try{ + if(indexLink.getLink().length()<1){ + refreshSuggest.setVisibility(View.VISIBLE); + refreshSuggest.setText("Enter Index Link"); + } + + if(radioIndexTypeButton ==null){ + refreshSuggest.setVisibility(View.VISIBLE); + refreshSuggest.setText("Select Index Type"); + } + if(indexLink.getUsername().length()<1 && indexLink.getPassword().length()<1){ + userNameView.setVisibility(View.GONE); + passWordView.setVisibility(View.GONE); + } + + indexLink.setType(radioIndexTypeButton.getText().toString()); + Thread thread = new Thread(new Runnable() { @Override public void run() { if(DatabaseClient.getInstance(MainActivity.mCtx).getAppDatabase().indexLinksDao().find(indexLink.getLink())!=null){ //refresh instead - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { refreshSuggest.setVisibility(View.VISIBLE); @@ -90,37 +115,47 @@ public void run() { }); }else { DatabaseClient.getInstance(MainActivity.mCtx).getAppDatabase().indexLinksDao().insert(indexLink); - SendPostRequest snd = new SendPostRequest(); save.setText("Adding"); - try { - if(indexLink.getUsername().length()<1 && indexLink.getPassword().length()<1){ - snd.postRequest(indexLink.getLink()); + switch(radioIndexTypeButton.getText().toString()){ + //Case statements + case "GDIndex": + try { + postRequestGDIndex(indexLink.getLink(),indexLink.getUsername(),indexLink.getPassword()); + } catch (IOException e) { + e.printStackTrace(); + } + break; + case "GoIndex": + try { + postRequestGoIndex(indexLink.getLink(),indexLink.getUsername(),indexLink.getPassword()); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + break; + case "MapleIndex": + try { + postRequestMapleIndex(indexLink.getLink(),indexLink.getUsername(),indexLink.getPassword()); + } catch (IOException e) { + e.printStackTrace(); + } + break; } - else { - snd.postRequest(indexLink.getLink(),indexLink.getUsername(),indexLink.getPassword()); - } - save.setText("Done"); - } catch (IOException e) { - e.printStackTrace(); - } + save.setText("Done"); } } }); - thread.start(); - if(save.getText().equals("Done")){ - getActivity().getSupportFragmentManager().popBackStack(); + thread.start(); + } catch (NullPointerException e) { + e.printStackTrace(); } - - + if(save.getText().equals("Done")){ + mActivity.getSupportFragmentManager().popBackStack(); + } } }); - - - - } } \ No newline at end of file diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/HomeFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/HomeFragment.java index d0b572f..4b7011c 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/HomeFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/HomeFragment.java @@ -11,7 +11,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -25,7 +24,7 @@ import java.util.List; -public class HomeFragment extends Fragment { +public class HomeFragment extends BaseFragment { List bannerList; @@ -54,8 +53,7 @@ public HomeFragment() { } public static HomeFragment newInstance(String param1, String param2) { - HomeFragment fragment = new HomeFragment(); - return fragment; + return new HomeFragment(); } @Override @@ -92,12 +90,12 @@ public void run() { .getAppDatabase() .fileDao() .getrecentlyadded(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { Log.i(" ", bannerList.toString()); - bannerRecycler = getView().findViewById(R.id.recentlyaddedrecycler); - bannerRecycler.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false)); + bannerRecycler = mActivity.findViewById(R.id.recentlyaddedrecycler); + bannerRecycler.setLayoutManager(new ScaleCenterItemLayoutManager(getContext(),RecyclerView.HORIZONTAL,false)); bannerRecycler.setHasFixedSize(true); bannerRecyclerAdapter = new BannerRecyclerAdapter(getContext(),bannerList,listener2); bannerRecycler.setAdapter(bannerRecyclerAdapter); @@ -119,11 +117,11 @@ public void run() { .getAppDatabase() .fileDao() .getrecentreleases(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { Log.i(" ", newmovieList.toString()); - recyclerView = getView().findViewById(R.id.recyclernewmovies); + recyclerView = mActivity.findViewById(R.id.recyclernewmovies); ScaleCenterItemLayoutManager linearLayoutManager = new ScaleCenterItemLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false); // recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false)); recyclerView.setLayoutManager(linearLayoutManager); @@ -150,11 +148,11 @@ public void run() { .getAppDatabase() .fileDao() .getTopRated(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { Log.i(" ", topRatedList.toString()); - topRatedRecycler = getView().findViewById(R.id.recyclertoprated); + topRatedRecycler = mActivity.findViewById(R.id.recyclertoprated); ScaleCenterItemLayoutManager linearLayoutManager = new ScaleCenterItemLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false); // recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false)); topRatedRecycler.setLayoutManager(linearLayoutManager); @@ -172,7 +170,7 @@ public void run() { void lastPlayed(){ setOnClickListner(); - lastPlayedTexView= getView().findViewById(R.id.LastPlayed); + lastPlayedTexView= mActivity.findViewById(R.id.LastPlayed); Thread thread = new Thread(new Runnable() { @@ -184,11 +182,11 @@ public void run() { .getAppDatabase() .fileDao() .getPlayed(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { Log.i(" ", lastPlayedList.toString()); - lastPlayedRecycler = getView().findViewById(R.id.recyclerlastplayed); + lastPlayedRecycler = mActivity.findViewById(R.id.recyclerlastplayed); ScaleCenterItemLayoutManager linearLayoutManager = new ScaleCenterItemLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false); // recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false)); lastPlayedRecycler.setLayoutManager(linearLayoutManager); @@ -201,10 +199,9 @@ public void run() { }}); thread.start(); if(lastPlayedList!=null){ - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { - lastPlayedTexView.setVisibility(View.VISIBLE); } }); @@ -216,29 +213,29 @@ private void setOnClickListner() { listener1 = new MovieRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getTitle()); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; listener2 = new BannerRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(bannerList.get(position).getTitle()); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(bannerList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; listener3 = new MovieRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(topRatedList.get(position).getTitle()); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(topRatedList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; listener4 = new MovieRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(lastPlayedList.get(position).getTitle()); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(lastPlayedList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; } diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/LibraryFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/LibraryFragment.java index 3d685f6..69a3ca4 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/LibraryFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/LibraryFragment.java @@ -1,5 +1,6 @@ package com.theflexproject.thunder.fragments; +import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -8,7 +9,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -21,20 +21,21 @@ import java.util.List; -public class LibraryFragment extends Fragment { +public class LibraryFragment extends BaseFragment { RecyclerView recyclerView; MovieRecyclerAdapterLibrary movieRecyclerAdapterLibrary; List newmovieList; MovieRecyclerAdapter.OnItemClickListener listener; + public static Context context; + public LibraryFragment() { // Required empty public constructor } public static LibraryFragment newInstance(String param1, String param2) { - LibraryFragment fragment = new LibraryFragment(); - return fragment; + return new LibraryFragment(); } @Override @@ -48,8 +49,8 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_library, container, false); + View view = inflater.inflate(R.layout.fragment_library, container, false); + return view; } @Override @@ -72,12 +73,12 @@ public void run() { .getAppDatabase() .fileDao() .getAll(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { Log.i(" ", newmovieList.toString()); - recyclerView = getView().findViewById(R.id.recyclernewmovies); - recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3)); + recyclerView = mActivity.findViewById(R.id.recyclerLibrary); + recyclerView.setLayoutManager(new GridLayoutManager(context, 3)); recyclerView.setHasFixedSize(true); movieRecyclerAdapterLibrary = new MovieRecyclerAdapterLibrary(getContext(),newmovieList,listener); recyclerView.setAdapter(movieRecyclerAdapterLibrary); @@ -93,8 +94,8 @@ private void setOnClickListner() { listener = new MovieRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getName(),1); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; } diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/MovieDetailsFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/MovieDetailsFragment.java index d9f5cef..1e5fc37 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/MovieDetailsFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/MovieDetailsFragment.java @@ -21,7 +21,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import com.bumptech.glide.Glide; import com.theflexproject.thunder.R; @@ -31,9 +30,8 @@ import com.theflexproject.thunder.utils.MovieQualityExtractor; import com.theflexproject.thunder.utils.sizetoReadablesize; -public class MovieDetailsFragment extends Fragment{ - String movieTitle; - int flag; +public class MovieDetailsFragment extends BaseFragment{ + String movieFileName; TextView titleText; TextView yearText; TextView size; @@ -48,19 +46,14 @@ public class MovieDetailsFragment extends Fragment{ public MovieDetailsFragment() { // Required empty public constructor } - public MovieDetailsFragment(String title){ - movieTitle=title; - } - public MovieDetailsFragment(String title, int flag){ - // if object created using this constructor then get file details - movieTitle=title; - this.flag =flag; + public MovieDetailsFragment(String name){ + movieFileName =name; } + public static MovieDetailsFragment newInstance(String param1, String param2) { - MovieDetailsFragment fragment = new MovieDetailsFragment(); - return fragment; + return new MovieDetailsFragment(); } @@ -93,30 +86,27 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat play = view.findViewById(R.id.play); download = view.findViewById(R.id.download); - if (flag == 1) { - loadDetailsFile(); - }else { - loadDetails(); - } - - + loadDetails(); //Play video play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - DatabaseClient.getInstance(getContext()).getAppDatabase().fileDao().updatePlayed(movieDetails.getName()); - } - }); - thread.start(); - - Intent in = new Intent(getActivity(), PlayerActivity.class); - in.putExtra("url",movieDetails.getUrlstring()); - startActivity(in); - Toast.makeText(getContext(),"Play",Toast.LENGTH_LONG).show(); + try { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + DatabaseClient.getInstance(getContext()).getAppDatabase().fileDao().updatePlayed(movieDetails.getName()); + } + }); + thread.start(); + + Intent in = new Intent(getActivity(), PlayerActivity.class); + in.putExtra("url",movieDetails.getUrlstring()); + startActivity(in); + Toast.makeText(getContext(),"Play",Toast.LENGTH_LONG).show(); + }catch (Exception e){ + e.printStackTrace(); + } } }); @@ -124,7 +114,7 @@ public void run() { download.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - DownloadManager manager = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE); + DownloadManager manager = (DownloadManager) mActivity.getSystemService(DOWNLOAD_SERVICE); Uri uri = Uri.parse(movieDetails.getUrlstring()); DownloadManager.Request request = new DownloadManager.Request(uri); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) @@ -137,76 +127,47 @@ public void onClick(View v) { } void loadDetails(){ - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - Log.i(" ", "in thread"); - movieDetails = DatabaseClient - .getInstance(mCtx) - .getAppDatabase() - .fileDao() - .getbyName(movieTitle); - Log.i("details ", movieDetails.toString()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - titleText.setText(movieDetails.getTitle()); - String year = movieDetails.getRelease_date(); - yearText.setText(year.substring(0,year.indexOf('-'))); - videoQuality.setText(MovieQualityExtractor.extractQualtiy(movieDetails.getName())); - size.setText(sizetoReadablesize.humanReadableByteCountBin(Long.parseLong(movieDetails.getSize()))); - overview.setText(movieDetails.getOverview()); - listOfFiles.setText(movieDetails.getUrlstring()); - Glide.with(getContext()) - .load(TMDB_IMAGE_BASE_URL+movieDetails.getPoster_path()) - .placeholder(new ColorDrawable(Color.BLACK)) - .into(poster); - } - }); - }}); - thread.start(); + try { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + movieDetails = DatabaseClient + .getInstance(mCtx) + .getAppDatabase() + .fileDao() + .getByFileName(movieFileName); + + Log.i("title",movieDetails.toString()); + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + if(movieDetails.getTitle()!=null){ + titleText.setText(movieDetails.getTitle()); + }else { + titleText.setText(movieDetails.getName()); + titleText.setTextSize(25); + yearText.setText("N/A"); + } + String year = movieDetails.getRelease_date(); + if(movieDetails.getRelease_date()!=null && movieDetails.getRelease_date().length()>1) {yearText.setText(year.substring(0,year.indexOf('-')));}else {yearText.setText("N/A");} + if(movieDetails.getOverview()!=null){overview.setText(movieDetails.getOverview());} + if(movieDetails.getPoster_path()!=null) { + Glide.with(mActivity) + .load(TMDB_IMAGE_BASE_URL + movieDetails.getPoster_path()) + .placeholder(new ColorDrawable(Color.BLACK)) + .into(poster); + } + String quality = MovieQualityExtractor.extractQualtiy(movieDetails.getName()); + if(quality!=null){ + videoQuality.setText(quality); + } + size.setText(sizetoReadablesize.humanReadableByteCountBin(Long.parseLong(movieDetails.getSize()))); + listOfFiles.setText(movieDetails.getUrlstring()); + } + }); + }}); + thread.start(); + }catch (NullPointerException exception){Log.i("Error",exception.toString());} } - - private void loadDetailsFile() { - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - Log.i(" ", "in thread"); - movieDetails = DatabaseClient - .getInstance(mCtx) - .getAppDatabase() - .fileDao() - .getByFileName(movieTitle); - Log.i("details ", movieDetails.toString()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - - if(movieDetails.getTitle()!=null){ - titleText.setText(movieDetails.getTitle()); - String year = movieDetails.getRelease_date(); - yearText.setText(year.substring(0,year.indexOf('-'))); - overview.setText(movieDetails.getOverview()); - Glide.with(getContext()) - .load(TMDB_IMAGE_BASE_URL+movieDetails.getPoster_path()) - .placeholder(new ColorDrawable(Color.BLACK)) - .into(poster); - }else { - titleText.setText(movieDetails.getName()); - titleText.setTextSize(25); - yearText.setText("N/A"); - } - videoQuality.setText(MovieQualityExtractor.extractQualtiy(movieDetails.getName())); - size.setText(sizetoReadablesize.humanReadableByteCountBin(Long.parseLong(movieDetails.getSize()))); - listOfFiles.setText(movieDetails.getUrlstring()); - - } - }); - }}); - thread.start(); - } - - - } \ No newline at end of file diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/SearchFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/SearchFragment.java index 01d32d3..73dea43 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/SearchFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/SearchFragment.java @@ -3,17 +3,18 @@ import static com.theflexproject.thunder.MainActivity.mCtx; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.EditText; import android.widget.ScrollView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -24,9 +25,11 @@ import com.theflexproject.thunder.model.File; import java.util.List; +import java.util.Timer; +import java.util.TimerTask; -public class SearchFragment extends Fragment { +public class SearchFragment extends BaseFragment { RecyclerView recyclerView; RecyclerView recyclerViewGenres; List genreList; @@ -34,7 +37,7 @@ public class SearchFragment extends Fragment { List newmovieList; MovieRecyclerAdapter.OnItemClickListener listener; - TextView searchBox; + EditText searchBox; Button search; ScrollView scrollview; @@ -67,6 +70,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat searchBox = view.findViewById(R.id.search_input); search = view.findViewById(R.id.search_button); scrollview= view.findViewById(R.id.scrollview); + recyclerView = mActivity.findViewById(R.id.recyclersearch); + scrollview.setVisibility(View.VISIBLE); + showSearchResults(); search.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -80,40 +86,59 @@ public void onClick(View view) { void showSearchResults(){ setOnClickListner(); - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - scrollview.setVisibility(View.VISIBLE); - } - }); - - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - Log.i(" ", "in thread"); - newmovieList = DatabaseClient - .getInstance(mCtx) - .getAppDatabase() - .fileDao() - .getSearchQuery(searchBox.getText().toString()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - Log.i(" ", newmovieList.toString()); - recyclerView = getView().findViewById(R.id.recyclersearch); - recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3)); - recyclerView.setHasFixedSize(true); - movieRecyclerAdapterLibrary = new MovieRecyclerAdapterLibrary(getContext(),newmovieList,listener); - recyclerView.setAdapter(movieRecyclerAdapterLibrary); - movieRecyclerAdapterLibrary.notifyDataSetChanged(); + try{ + searchBox.addTextChangedListener( + new TextWatcher() { + @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + private Timer timer = new Timer(); + private final long DELAY = 500; // milliseconds + + @Override + public void afterTextChanged(final Editable s) { + timer.cancel(); + timer = new Timer(); + timer.schedule( + new TimerTask() { + @Override + public void run() { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + Log.i(" ", "in thread"); + newmovieList = DatabaseClient + .getInstance(mCtx) + .getAppDatabase() + .fileDao() + .getSearchQuery(searchBox.getText().toString()); + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Log.i(" ", newmovieList.toString()); + recyclerView.setLayoutManager(new GridLayoutManager(mActivity , 3)); + recyclerView.setHasFixedSize(true); + movieRecyclerAdapterLibrary = new MovieRecyclerAdapterLibrary(mActivity,newmovieList,listener); + recyclerView.setAdapter(movieRecyclerAdapterLibrary); + movieRecyclerAdapterLibrary.notifyDataSetChanged(); + } + }); + }}); + thread.start(); + } + }, + DELAY + ); + } } - }); - }}); - thread.start(); + ); + }catch (Exception e){ + Log.i(e.toString(),"Exception"); + } } + /** To-Do */ void showbyGenre(){ // Thread thread = new Thread(new Runnable() { // @Override @@ -144,8 +169,8 @@ private void setOnClickListner() { listener = new MovieRecyclerAdapter.OnItemClickListener() { @Override public void onClick(View view, int position) { - MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getName(),1); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); + MovieDetailsFragment movieDetailsFragment = new MovieDetailsFragment(newmovieList.get(position).getName()); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container,movieDetailsFragment).addToBackStack(null).commit(); } }; } diff --git a/app/src/main/java/com/theflexproject/thunder/fragments/SettingsFragment.java b/app/src/main/java/com/theflexproject/thunder/fragments/SettingsFragment.java index cc5fc9d..67362fb 100644 --- a/app/src/main/java/com/theflexproject/thunder/fragments/SettingsFragment.java +++ b/app/src/main/java/com/theflexproject/thunder/fragments/SettingsFragment.java @@ -10,7 +10,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -23,12 +22,7 @@ import java.util.List; import java.util.concurrent.Executors; -/** - * A simple {@link Fragment} subclass. - * Use the {@link SettingsFragment#newInstance} factory method to - * create an instance of this fragment. - */ -public class SettingsFragment extends Fragment { +public class SettingsFragment extends BaseFragment { List list; private RecyclerView recyclerView; FloatingActionButton floatingActionButton; @@ -64,7 +58,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat @Override public void run() { list = DatabaseClient.getInstance(mCtx).getAppDatabase().indexLinksDao().getAll(); - getActivity().runOnUiThread(new Runnable() { + mActivity.runOnUiThread(new Runnable() { @Override public void run() { recyclerView = view.findViewById(R.id.recyclerviewindexes); @@ -85,16 +79,16 @@ public void run() { @Override public void onClick(View view) { AddNewIndexFragment nextFrag= new AddNewIndexFragment(); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.containersettings, nextFrag).addToBackStack(null).commit(); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.containersettings, nextFrag).addToBackStack(null).commit(); } }); - info = getActivity().findViewById(R.id.about); + info = mActivity.findViewById(R.id.about); info.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AboutFragment fragment = new AboutFragment(); - getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.containersettings,fragment).addToBackStack(null).commit(); + mActivity.getSupportFragmentManager().beginTransaction().replace(R.id.containersettings,fragment).addToBackStack(null).commit(); } }); diff --git a/app/src/main/java/com/theflexproject/thunder/model/IndexLink.java b/app/src/main/java/com/theflexproject/thunder/model/IndexLink.java index 36ced2e..8987b96 100644 --- a/app/src/main/java/com/theflexproject/thunder/model/IndexLink.java +++ b/app/src/main/java/com/theflexproject/thunder/model/IndexLink.java @@ -13,6 +13,15 @@ public class IndexLink{ public String link; public String username; public String password; + public String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } public int getId() { return id; diff --git a/app/src/main/java/com/theflexproject/thunder/model/ResFormat.java b/app/src/main/java/com/theflexproject/thunder/model/ResFormat.java index f98ccbe..a31f633 100644 --- a/app/src/main/java/com/theflexproject/thunder/model/ResFormat.java +++ b/app/src/main/java/com/theflexproject/thunder/model/ResFormat.java @@ -13,6 +13,16 @@ public class ResFormat{ public Data data; public String nextPageToken; public String curPageIndex; + public int code; + + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } public String getNextPageToken() { return nextPageToken; diff --git a/app/src/main/java/com/theflexproject/thunder/player/PlayerActivity.java b/app/src/main/java/com/theflexproject/thunder/player/PlayerActivity.java index cd35443..5aba9d1 100644 --- a/app/src/main/java/com/theflexproject/thunder/player/PlayerActivity.java +++ b/app/src/main/java/com/theflexproject/thunder/player/PlayerActivity.java @@ -279,7 +279,7 @@ protected void clearStartPosition() { } private void showControls() { - debugRootView.setVisibility(View.VISIBLE); + } private void showToast(int messageId) { @@ -307,7 +307,6 @@ public void onPlayerError(PlaybackException error) { player.seekToDefaultPosition(); player.prepare(); } else { - showControls(); } } diff --git a/app/src/main/java/com/theflexproject/thunder/utils/MovieQualityExtractor.java b/app/src/main/java/com/theflexproject/thunder/utils/MovieQualityExtractor.java index 60e1afd..1672450 100644 --- a/app/src/main/java/com/theflexproject/thunder/utils/MovieQualityExtractor.java +++ b/app/src/main/java/com/theflexproject/thunder/utils/MovieQualityExtractor.java @@ -10,7 +10,6 @@ public static String extractQualtiy(String name){ if(Pattern.compile(Pattern.quote("HDR"), Pattern.CASE_INSENSITIVE).matcher(name).find() && name.contains("1080")) return "1080p HDR"; if(Pattern.compile(Pattern.quote("Dolby Vision"), Pattern.CASE_INSENSITIVE).matcher(name).find() || - Pattern.compile(Pattern.quote("DV"), Pattern.CASE_INSENSITIVE).matcher(name).find() || Pattern.compile(Pattern.quote("DVSUX"), Pattern.CASE_INSENSITIVE).matcher(name).find()) return "Dolby Vision"; if(name.contains("2160")) return "2160p"; diff --git a/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor.java b/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor.java index d365473..d06a97f 100644 --- a/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor.java +++ b/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor.java @@ -16,13 +16,14 @@ public static MovieTitleExtractor instance() { // singleton } - public static String getTitleYear(String matchString) { + public static String[] getTitleYear(String matchString) { Matcher m = NAME_YEAR_SCENE_PATTERN.matcher(matchString); if (m.matches()) { String name = StringUtils.replaceAll(m.group(1), " ", JUNK_PATTERN); name = ParseUtils.removeInnerAndOutterSeparatorJunk(name); String year = m.group(2); - return name; + String[] nameYear = {name,year}; + return nameYear; } return null; } diff --git a/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor2.java b/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor2.java index f9cbe1b..c378a2e 100644 --- a/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor2.java +++ b/app/src/main/java/com/theflexproject/thunder/utils/MovieTitleExtractor2.java @@ -23,7 +23,7 @@ private MovieTitleExtractor2() { } - public static String getTitle2(String input) { + public static String[] getTitle2(String input) { String name = input; // extract the last year from the string @@ -61,7 +61,8 @@ public static String getTitle2(String input) { name = cutOffBeforeFirstMatch(name, GARBAGE_LOWERCASE); name = name.trim(); - return name; + String[] nameYear2 ={name,year}; + return nameYear2; } // Common garbage in movies names to determine where the garbage starts in the name diff --git a/app/src/main/java/com/theflexproject/thunder/utils/SendGetRequestTMDB.java b/app/src/main/java/com/theflexproject/thunder/utils/SendGetRequestTMDB.java index 00c476a..a9855a0 100644 --- a/app/src/main/java/com/theflexproject/thunder/utils/SendGetRequestTMDB.java +++ b/app/src/main/java/com/theflexproject/thunder/utils/SendGetRequestTMDB.java @@ -5,9 +5,10 @@ import android.util.Log; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import com.theflexproject.thunder.model.File; import com.theflexproject.thunder.model.TMDBResponse; -import com.google.gson.Gson; import java.io.BufferedReader; import java.io.IOException; @@ -16,20 +17,40 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.NoSuchElementException; + +import me.xdrop.fuzzywuzzy.FuzzySearch; +import me.xdrop.fuzzywuzzy.model.ExtractedResult; public class SendGetRequestTMDB { - void sendGet(File file){ + + + static void sendGet(File file){ String finalurl=""; + String[] titleYear1 = MovieTitleExtractor.getTitleYear(file.getName().replaceAll("Copy of ","")); + String[] titleYear2 = MovieTitleExtractor2.getTitle2(file.getName().replaceAll("Copy of ","")); + String titleFromFile1 = "",titleFromFile2 = "", yearFromFile1 = "", yearFromFile2 =""; + if(titleYear1 != null){ + titleFromFile1 = titleYear1[0]; + }else{ + titleFromFile2 = titleYear2[0]; + } + if(titleYear1 != null){ + yearFromFile1 = titleYear1[0]; + }else{ + yearFromFile2 = titleYear2[0]; + } try { try{ if(MovieTitleExtractor.getTitleYear(file.getName())!=null) { - finalurl = TMDB_GET_REQUEST_BASE_URL +TMDB_API_KEY+"&language=en-US&page=1&include_adult=true&query=" - + URLEncoder.encode(MovieTitleExtractor.getTitleYear(file.getName()),"UTF-8"); + finalurl = TMDB_GET_REQUEST_BASE_URL +TMDB_API_KEY+"&language=en-US&page=1&include_adult=false&query=" + + URLEncoder.encode(titleFromFile1 ,"UTF-8"); } else{ - finalurl = TMDB_GET_REQUEST_BASE_URL+TMDB_API_KEY+"&language=en-US&page=1&include_adult=true&query=" - +URLEncoder.encode(MovieTitleExtractor2.getTitle2(file.getName()),"UTF-8"); + finalurl = TMDB_GET_REQUEST_BASE_URL+TMDB_API_KEY+"&language=en-US&page=1&include_adult=false&query=" + +URLEncoder.encode(titleFromFile2 ,"UTF-8"); } }catch (Exception e){ Log.i("exc",e.toString()); @@ -57,18 +78,67 @@ void sendGet(File file){ } Gson gson = new Gson(); TMDBResponse tmdbResponse = gson.fromJson(response.toString(), TMDBResponse.class); + + + //New Changes + ArrayList titlesFromTMDB = new ArrayList<>(); + ArrayList yearsFromTMDB = new ArrayList<>(); + ArrayList titlesandYearsFromTMDB = new ArrayList<>(); + for (int i = 0; i < tmdbResponse.results.size(); i++) { + titlesFromTMDB.add(tmdbResponse.results.get(i).getTitle()); + yearsFromTMDB.add(tmdbResponse.results.get(i).getRelease_date()); + titlesandYearsFromTMDB.add(tmdbResponse.results.get(i).getTitle()+" "+tmdbResponse.results.get(i).getRelease_date()); + } + + ExtractedResult result; + String finalTitle ; + int finalIndex = 0; + + Log.i("list of tmdb" , titlesFromTMDB.toString()); + try{ + if(titleFromFile1 != null){ + result = FuzzySearch.extractOne(titleFromFile1 , titlesFromTMDB); + Log.i(result.toString(),"result"); + if(result.getScore()>60){ + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString(),finalTitle); + }else { + result = FuzzySearch.extractOne(titleFromFile1+yearFromFile1 , titlesandYearsFromTMDB); + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString(),finalTitle); + } + + }else { + result = FuzzySearch.extractOne(titleFromFile2+" "+yearFromFile2, titlesFromTMDB); + if(result.getScore()>60){ + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString(),finalTitle); + }else { + result = FuzzySearch.extractOne(titleFromFile2+yearFromFile2 , titlesandYearsFromTMDB); + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString(),finalTitle); + } + } + }catch (Exception e){e.printStackTrace();} + + + + if(tmdbResponse.results.size()>0){ - file.setBackdrop_path(tmdbResponse.results.get(0).getBackdrop_path()); - file.setTitle(tmdbResponse.results.get(0).getTitle()); - file.setOriginal_language(tmdbResponse.results.get(0).getOriginal_language()); - file.setOriginal_title(tmdbResponse.results.get(0).getOriginal_title()); - file.setOverview(tmdbResponse.results.get(0).getOverview()); - file.setPopularity(tmdbResponse.results.get(0).getPopularity()); - file.setPoster_path(tmdbResponse.results.get(0).getPoster_path()); - file.setRelease_date(tmdbResponse.results.get(0).getRelease_date()); + file.setBackdrop_path(tmdbResponse.results.get(finalIndex).getBackdrop_path()); + file.setTitle(tmdbResponse.results.get(finalIndex).getTitle()); + file.setOriginal_language(tmdbResponse.results.get(finalIndex).getOriginal_language()); + file.setOriginal_title(tmdbResponse.results.get(finalIndex).getOriginal_title()); + file.setOverview(tmdbResponse.results.get(finalIndex).getOverview()); + file.setPopularity(tmdbResponse.results.get(finalIndex).getPopularity()); + file.setPoster_path(tmdbResponse.results.get(finalIndex).getPoster_path()); + file.setRelease_date(tmdbResponse.results.get(finalIndex).getRelease_date()); // file.setGenre_ids(tmdbResponse.results.get(0).getGenre_ids()); - - Log.i("sendGet: ",tmdbResponse.results.get(0).toString()); + Log.i("sendGet: ",tmdbResponse.results.get(finalIndex).toString()); } @@ -81,4 +151,103 @@ void sendGet(File file){ // return file; } -} + + + static void sendGet2(File file) throws IOException { + String finalurl = ""; + String[] titleYear1 = MovieTitleExtractor.getTitleYear(file.getName().replaceAll("Copy of " , "")); + String[] titleYear2 = MovieTitleExtractor2.getTitle2(file.getName().replaceAll("Copy of " , "")); + + String + titleFromFile1 = "", + titleFromFile2 = "", + yearFromFile1 = ParseUtils.yearExtractor(file.getName()).second, + yearFromFile2 = ParseUtils.yearExtractor(file.getName()).second; + + ArrayList titlesandYearsFromTMDB = new ArrayList<>(); + + if (titleYear1 != null) { + titleFromFile1 = titleYear1[0]; + } else { + titleFromFile2 = titleYear2[0]; + } + try { + if (MovieTitleExtractor.getTitleYear(file.getName()) != null) { + finalurl = TMDB_GET_REQUEST_BASE_URL + TMDB_API_KEY + "&language=en-US&page=1&include_adult=false&query=" + + URLEncoder.encode(titleFromFile1 , "UTF-8"); + } else { + finalurl = TMDB_GET_REQUEST_BASE_URL + TMDB_API_KEY + "&language=en-US&page=1&include_adult=false&query=" + + URLEncoder.encode(titleFromFile2 , "UTF-8"); + } + } catch (Exception e) { + Log.i("exc" , e.toString()); + e.printStackTrace(); + } + StringBuilder response = new StringBuilder(); + try { + URL url = new URL(finalurl); + Log.i("movie title" , finalurl); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + int responseCode = con.getResponseCode(); + Log.i("tmdb api response" , String.valueOf(responseCode)); + if (responseCode == HttpURLConnection.HTTP_OK) { // success + BufferedReader in = new BufferedReader(new InputStreamReader( + con.getInputStream())); + String inputLine; + response = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + } else { + System.out.println("GET request did not work"); + } + Gson gson = new Gson(); + TMDBResponse tmdbResponse = gson.fromJson(response.toString() , TMDBResponse.class); + + for (int i = 0; i < tmdbResponse.results.size(); i++) { + String releaseDate = tmdbResponse.results.get(i).getRelease_date(); + if (releaseDate != null) + titlesandYearsFromTMDB.add(tmdbResponse.results.get(i).getTitle() + " " + releaseDate.split("-")[0]); + } + Log.i("result" , titlesandYearsFromTMDB.toString()); + ExtractedResult result; + String finalTitle; + int finalIndex = 0; + try { + if (titleFromFile1 != null && yearFromFile1 != null) { + result = FuzzySearch.extractOne(titleFromFile1 + " " + yearFromFile1 , titlesandYearsFromTMDB); + Log.i("result" , result.toString()); + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString() , finalTitle); + + } else { + result = FuzzySearch.extractOne(titleFromFile2 + " " + yearFromFile2 , titlesandYearsFromTMDB); + finalTitle = result.getString(); + finalIndex = result.getIndex(); + Log.i(result.toString() , finalTitle); + } + + if (tmdbResponse.results.size() > 0) { + file.setBackdrop_path(tmdbResponse.results.get(finalIndex).getBackdrop_path()); + file.setTitle(tmdbResponse.results.get(finalIndex).getTitle()); + file.setOriginal_language(tmdbResponse.results.get(finalIndex).getOriginal_language()); + file.setOriginal_title(tmdbResponse.results.get(finalIndex).getOriginal_title()); + file.setOverview(tmdbResponse.results.get(finalIndex).getOverview()); + file.setPopularity(tmdbResponse.results.get(finalIndex).getPopularity()); + file.setPoster_path(tmdbResponse.results.get(finalIndex).getPoster_path()); + file.setRelease_date(tmdbResponse.results.get(finalIndex).getRelease_date()); + Log.i("sendGet: " , tmdbResponse.results.get(finalIndex).toString()); + } + } catch (JsonSyntaxException | NoSuchElementException elementException) { + elementException.printStackTrace(); + } + } catch (IOException | JsonSyntaxException e) { + e.printStackTrace(); + } + if(file.getTitle()==null){sendGet(file);} + + } + } \ No newline at end of file diff --git a/app/src/main/java/com/theflexproject/thunder/utils/SendPostRequest.java b/app/src/main/java/com/theflexproject/thunder/utils/SendPostRequest.java index a720a1a..2d09fd0 100644 --- a/app/src/main/java/com/theflexproject/thunder/utils/SendPostRequest.java +++ b/app/src/main/java/com/theflexproject/thunder/utils/SendPostRequest.java @@ -1,98 +1,47 @@ package com.theflexproject.thunder.utils; import static com.theflexproject.thunder.MainActivity.mCtx; +import static com.theflexproject.thunder.utils.SendGetRequestTMDB.sendGet2; import android.os.Build; import android.util.Log; import androidx.annotation.RequiresApi; +import com.google.gson.Gson; import com.theflexproject.thunder.database.DatabaseClient; import com.theflexproject.thunder.model.File; import com.theflexproject.thunder.model.ResFormat; -import com.google.gson.Gson; + +import org.json.JSONException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Base64; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; public class SendPostRequest { -private String nextPageToken = ""; -private int pageIndex = 0; - - @RequiresApi(api = Build.VERSION_CODES.O) - public void postRequest(String urlString) throws IOException { - if(urlString.charAt(urlString.length()-1)!='/'){urlString+='/';} - URL url = new URL(urlString); - Map params = new LinkedHashMap<>(); - params.put("authorization", "Basic Og=="); - params.put("page_token", ""); - params.put("page_index", 0); - - StringBuilder postData = new StringBuilder(); - for (Map.Entry param : params.entrySet()) { - if (postData.length() != 0) postData.append('&'); - postData.append(URLEncoder.encode(param.getKey(), "UTF-8" )); - postData.append('='); - postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); - } - byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8); - - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - conn.setDoOutput(true); - conn.getOutputStream().write(postDataBytes); - - Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - - StringBuilder sb = new StringBuilder(); - for (int c; (c = in.read()) >= 0;) - sb.append((char)c); - StringBuilder reverseSb = sb.reverse(); - String encodedString = reverseSb.substring(24,reverseSb.length()-20); - byte[] decodedBytes = Base64.getDecoder().decode(encodedString); - String decodedString = new String(decodedBytes,StandardCharsets.UTF_8); - - Gson gson = new Gson(); - ResFormat target = gson.fromJson(decodedString, ResFormat.class); - - Log.i("postRequest: ",target.toString()); - - DatabaseClient.getInstance(mCtx).getAppDatabase().resFormatDao().insert(target); - SendGetRequestTMDB sendGetRequestTMDB = new SendGetRequestTMDB(); - for (int i = 0; i < target.data.files.size(); i++) { - File file = target.data.files.get(i); - if(DatabaseClient.getInstance(mCtx).getAppDatabase().fileDao().getByFileName(file.getName())==null && - file.getMimeType().equals("video/x-matroska")||file.getMimeType().equals("video/mp4")){ - file.setUrlstring(url+file.getName()); - sendGetRequestTMDB.sendGet(file); - DatabaseClient.getInstance(mCtx).getAppDatabase().fileDao().insert(target.data.files.get(i)); - } - } - if(target.nextPageToken!=null){ - nextPageToken =target.nextPageToken; - pageIndex++; - postRequest(urlString); - } - - - } +private static String nextPageToken = ""; +private static int pageIndex = 0; +private static String user = ""; +private static String pass = ""; @RequiresApi(api = Build.VERSION_CODES.O) - public void postRequest(String urlString, String user, String pass) throws IOException { + public static void postRequestGDIndex(String urlString, String user, String pass) throws IOException { if(urlString.charAt(urlString.length()-1)!='/'){urlString+='/';} URL url = new URL(urlString); String user_pass = user+":"+pass; @@ -122,6 +71,15 @@ public void postRequest(String urlString, String user, String pass) throws IOExc conn.setDoOutput(true); conn.getOutputStream().write(postDataBytes); + + int code = conn.getResponseCode(); + System.out.println(("HTTP CODE" + String.valueOf(code))); + + /** Infinite recursion not a good solution */ + if(code==500){ + postRequestGDIndex(urlString,user,pass); + } + Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); StringBuilder sb = new StringBuilder(); @@ -131,30 +89,198 @@ public void postRequest(String urlString, String user, String pass) throws IOExc String encodedString = reverseSb.substring(24,reverseSb.length()-20); byte[] decodedBytes = Base64.getDecoder().decode(encodedString); String decodedString = new String(decodedBytes,StandardCharsets.UTF_8); - Gson gson = new Gson(); ResFormat target = gson.fromJson(decodedString, ResFormat.class); - Log.i("postRequest: ",target.toString()); + try{ + Log.i("Error",decodedString.toString()); + }catch (NullPointerException w){ w.toString();} DatabaseClient.getInstance(mCtx).getAppDatabase().resFormatDao().insert(target); - SendGetRequestTMDB sendGetRequestTMDB = new SendGetRequestTMDB(); - for (int i = 0; i < target.data.files.size(); i++) { + + List folders = new ArrayList<>(); + + try{ + for (int i = 0; i < target.data.files.size(); i++) { File file = target.data.files.get(i); - if(file.getMimeType().equals("video/x-matroska")||file.getMimeType().equals("video/mp4")){ + if(file.getMimeType().equals("video/x-matroska") + ||file.getMimeType().equals("video/mp4") + || file.getMimeType().equals("video/x-msvideo") + || file.getMimeType().equals("video/mpeg") + || file.getMimeType().equals("video/webm")){ file.setUrlstring(url+file.getName()); - sendGetRequestTMDB.sendGet(file); + sendGet2(file); DatabaseClient.getInstance(mCtx).getAppDatabase().fileDao().insert(target.data.files.get(i)); + }else if( file.getMimeType().equals("application/vnd.google-apps.folder")){ + folders.add(url+file.getName()+"/"); } } + }catch (NullPointerException e){Log.i("Exception",e.toString());} + Log.i("Folder",folders.toString()); if(target.nextPageToken!=null){ nextPageToken =target.nextPageToken; pageIndex++; - postRequest(urlString,user,pass); + postRequestGDIndex(urlString,user,pass); + } + for (int i = 0; i < folders.size(); i++) { + pageIndex = 0; + nextPageToken = ""; + postRequestGDIndex(folders.get(i),user,pass); + Log.i("Folder",folders.get(i).toString()); + } + + + + } + + @RequiresApi(api = Build.VERSION_CODES.O) + public static void postRequestGoIndex(String urlString, String user, String pass) throws IOException, JSONException { + if (urlString.charAt(urlString.length() - 1) != '/') { + urlString += '/'; + } + + URL url = new URL(urlString); + + String user_pass = user + ":" + pass; + byte[] user_pass_array = user_pass.getBytes(StandardCharsets.UTF_8); + String authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(user_pass_array); + System.out.println(authHeaderValue); + + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setRequestProperty("Accept", "application/json"); + conn.setRequestProperty("Authorization", authHeaderValue); + conn.setDoOutput(true); + String json = "{ \"q\":\"\",\"password\": null , \"page_index\":" + pageIndex + "}"; + OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); + OutputStream os = conn.getOutputStream(); + os.write(json.getBytes(StandardCharsets.UTF_8)); + os.close(); + int code = conn.getResponseCode(); + System.out.println(("HTTP CODE" + String.valueOf(code))); + + /** Infinite recursion not a good solution */ + if(code==500){ + postRequestGoIndex(urlString,user,pass); + } + + BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream(),"utf-8")); + String line = null; + StringBuilder sb = new StringBuilder(); + for (int c; (c = br.read()) >= 0;) + sb.append((char)c); + br.close(); + System.out.println(""+sb.toString()); + Gson gson = new Gson(); + ResFormat outPutJson = gson.fromJson(String.valueOf(sb), ResFormat.class); + + DatabaseClient.getInstance(mCtx).getAppDatabase().resFormatDao().insert(outPutJson); + + if(outPutJson.data.files==null){ + postRequestGoIndex(urlString,user,pass); + } + + List folders = new ArrayList<>(); + + for (int i = 0; i < outPutJson.data.files.size(); i++) { + File file = outPutJson.data.files.get(i); + if(file.getMimeType().equals("video/x-matroska") + ||file.getMimeType().equals("video/mp4") + || file.getMimeType().equals("video/x-msvideo") + || file.getMimeType().equals("video/mpeg") + || file.getMimeType().equals("video/webm")) + { + file.setUrlstring(url+file.getName()); + sendGet2(file); + DatabaseClient.getInstance(mCtx).getAppDatabase().fileDao().insert(outPutJson.data.files.get(i)); + }else if( file.getMimeType().equals("application/vnd.google-apps.folder")){ + folders.add(url+file.getName()); + } + + } + + if(outPutJson.nextPageToken!=null){ + nextPageToken =outPutJson.nextPageToken; + pageIndex++; + postRequestGoIndex(urlString,user,pass); } + for (int i = 0; i < folders.size(); i++) { + pageIndex = 0; + nextPageToken = ""; + postRequestGoIndex(folders.get(i),user,pass); + Log.i("Folder",folders.get(i).toString()); + } } + @RequiresApi(api = Build.VERSION_CODES.O) + public static void postRequestMapleIndex(String urlString, String user, String pass) throws IOException { + URL url = new URL(urlString); + + if (urlString.charAt(urlString.length() - 1) != '/') { + urlString += '/'; + } + urlString +="?rootId=root"; + + String user_pass = user + ":" + pass; + byte[] user_pass_array = user_pass.getBytes(StandardCharsets.UTF_8); + String authHeaderValue = "Basic " + Base64.getEncoder().encodeToString(user_pass_array); + System.out.println(authHeaderValue); + + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setRequestProperty("Accept", "application/json"); + conn.setRequestProperty("Authorization", authHeaderValue); + conn.setDoOutput(true); + + BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream(),"utf-8")); + String line = null; + StringBuilder sb = new StringBuilder(); + for (int c; (c = br.read()) >= 0;) + sb.append((char)c); + br.close(); + System.out.println(""+sb.toString()); + Gson gson = new Gson(); + ResFormat outPutJson = gson.fromJson(String.valueOf(sb), ResFormat.class); + Log.i(" json",outPutJson.toString()); + DatabaseClient.getInstance(mCtx).getAppDatabase().resFormatDao().insert(outPutJson); + + List folders = new ArrayList<>(); + + for (int i = 0; i < outPutJson.data.files.size(); i++) { + File file = outPutJson.data.files.get(i); + if(file.getMimeType().equals("video/x-matroska") + ||file.getMimeType().equals("video/mp4") + || file.getMimeType().equals("video/x-msvideo") + || file.getMimeType().equals("video/mpeg") + || file.getMimeType().equals("video/webm")) + { + file.setUrlstring(url+file.getName()); + sendGet2(file); + DatabaseClient.getInstance(mCtx).getAppDatabase().fileDao().insert(outPutJson.data.files.get(i)); + }else if( file.getMimeType().equals("application/vnd.google-apps.folder")){ + folders.add(url+file.getName()); + } + } + + if(outPutJson.nextPageToken!=null){ + nextPageToken =outPutJson.nextPageToken; + pageIndex++; + postRequestMapleIndex(urlString,user,pass); + } + + for (int i = 0; i < folders.size(); i++) { + pageIndex = 0; + nextPageToken = ""; + postRequestMapleIndex(folders.get(i),user,pass); + Log.i("Folder",folders.get(i).toString()); + } + + + + } } diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d1..0000000 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 07d5da9..0000000 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_recycler_view_layout.xml b/app/src/main/res/layout/activity_recycler_view_layout.xml index 277a95e..d2385d2 100644 --- a/app/src/main/res/layout/activity_recycler_view_layout.xml +++ b/app/src/main/res/layout/activity_recycler_view_layout.xml @@ -63,6 +63,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView2" /> + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/rb_group" /> +