From ee0e8aa83edb0ed5b80c8698090e0245bf8d9a0f Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Mon, 18 Mar 2019 11:05:00 +0100 Subject: [PATCH] Delete unused code --- .../readrops/app/activities/MainActivity.java | 4 - .../app/repositories/ARepository.java | 20 --- .../app/repositories/LocalFeedRepository.java | 3 +- .../app/viewmodels/MainViewModel.java | 5 - .../com/readrops/app/views/AddFeedDialog.java | 150 ------------------ .../app/views/AddFeedListAdapter.java | 75 --------- .../readrops/app/views/SimpleCallback.java | 8 - 7 files changed, 1 insertion(+), 264 deletions(-) delete mode 100644 app/src/main/java/com/readrops/app/views/AddFeedDialog.java delete mode 100644 app/src/main/java/com/readrops/app/views/AddFeedListAdapter.java delete mode 100644 app/src/main/java/com/readrops/app/views/SimpleCallback.java diff --git a/app/src/main/java/com/readrops/app/activities/MainActivity.java b/app/src/main/java/com/readrops/app/activities/MainActivity.java index 6e957116..d1d79c08 100644 --- a/app/src/main/java/com/readrops/app/activities/MainActivity.java +++ b/app/src/main/java/com/readrops/app/activities/MainActivity.java @@ -2,8 +2,6 @@ package com.readrops.app.activities; import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; @@ -36,7 +34,6 @@ import com.readrops.app.database.entities.Feed; import com.readrops.app.views.MainItemListAdapter; import com.readrops.app.viewmodels.MainViewModel; import com.readrops.app.R; -import com.readrops.app.views.SimpleCallback; import com.readrops.app.database.pojo.ItemWithFeed; import com.readrops.app.database.entities.Item; import com.readrops.app.utils.GlideApp; @@ -53,7 +50,6 @@ import io.reactivex.Observer; import io.reactivex.SingleObserver; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; -import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { diff --git a/app/src/main/java/com/readrops/app/repositories/ARepository.java b/app/src/main/java/com/readrops/app/repositories/ARepository.java index a713b5fc..b8ff4477 100644 --- a/app/src/main/java/com/readrops/app/repositories/ARepository.java +++ b/app/src/main/java/com/readrops/app/repositories/ARepository.java @@ -2,8 +2,6 @@ package com.readrops.app.repositories; import android.app.Application; import android.graphics.Bitmap; -import android.os.Handler; -import android.os.Looper; import android.support.v7.graphics.Palette; import android.util.Patterns; @@ -11,7 +9,6 @@ import com.readrops.app.database.pojo.FeedWithFolder; import com.readrops.app.utils.FeedInsertionResult; import com.readrops.app.utils.HtmlParser; import com.readrops.app.utils.Utils; -import com.readrops.app.views.SimpleCallback; import com.readrops.app.database.Database; import com.readrops.app.database.entities.Feed; import com.readrops.app.database.entities.Folder; @@ -29,7 +26,6 @@ import io.reactivex.Single; public abstract class ARepository { protected Executor executor; - protected SimpleCallback callback; protected Database database; @@ -38,10 +34,6 @@ public abstract class ARepository { this.database = Database.getInstance(application); } - public void setCallback(SimpleCallback callback) { - this.callback = callback; - } - public abstract Observable sync(List feeds); public abstract void addFeed(ParsingResult result); @@ -94,16 +86,4 @@ public abstract class ARepository { if (palette.getMutedSwatch() != null) feed.setBackgroundColor(palette.getMutedSwatch().getRgb()); } - - protected void failureCallBackInMainThread(Exception e) { - Handler handler = new Handler(Looper.getMainLooper()); - - handler.post(() -> callback.onFailure(e)); - } - - protected void postCallBackSuccess() { - // we go back to the main thread - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(() -> callback.onSuccess()); - } } diff --git a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java index 046572e1..c9fdbe58 100644 --- a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java @@ -116,9 +116,8 @@ public class LocalFeedRepository extends ARepository { insertFeed(queryResult.getFeed(), queryResult.getRssType()); } - postCallBackSuccess(); } catch (Exception e) { - failureCallBackInMainThread(e); + } }); } diff --git a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java index 0b186d2b..2dca2247 100644 --- a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java +++ b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java @@ -8,7 +8,6 @@ import android.support.annotation.NonNull; import com.readrops.app.database.entities.Feed; import com.readrops.app.database.pojo.ItemWithFeed; import com.readrops.app.repositories.LocalFeedRepository; -import com.readrops.app.views.SimpleCallback; import com.readrops.app.utils.ParsingResult; import java.util.List; @@ -33,10 +32,6 @@ public class MainViewModel extends AndroidViewModel { return itemsWithFeed; } - public void setSimpleCallback(SimpleCallback simpleCallback) { - repository.setCallback(simpleCallback); - } - public Observable sync(List feeds) { return repository.sync(feeds); } diff --git a/app/src/main/java/com/readrops/app/views/AddFeedDialog.java b/app/src/main/java/com/readrops/app/views/AddFeedDialog.java deleted file mode 100644 index 2c148a06..00000000 --- a/app/src/main/java/com/readrops/app/views/AddFeedDialog.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.readrops.app.views; - -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.support.annotation.NonNull; -import android.support.annotation.StringRes; -import android.support.design.widget.TextInputEditText; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.util.Patterns; -import android.view.View; -import android.widget.Button; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.readrops.app.R; -import com.readrops.app.activities.MainActivity; -import com.readrops.app.utils.Utils; -import com.readrops.app.utils.HtmlParser; -import com.readrops.app.utils.ParsingResult; -import com.readrops.readropslibrary.localfeed.RSSQuery; - -import java.net.UnknownHostException; -import java.util.List; -import java.util.concurrent.Executors; - -public class AddFeedDialog extends Dialog implements View.OnClickListener { - - private int layoutId; - private Button button; - private TextInputEditText textInputEditText; - private ProgressBar progressBar; - private TextView errorTextView; - - private RecyclerView recyclerView; - private AddFeedListAdapter adapter; - - public AddFeedDialog(@NonNull Context context, int layoutId) { - super(context); - if (context instanceof Activity) - setOwnerActivity((Activity) context); - this.layoutId = layoutId; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(layoutId); - - button = findViewById(R.id.add_feed_validate); - button.setOnClickListener(this); - textInputEditText = findViewById(R.id.add_feed_text_input); - progressBar = findViewById(R.id.add_feed_progressbar); - errorTextView = findViewById(R.id.add_feed_error); - } - - - @Override - public void onClick(View view) { - if (isValidUrl()) { - if (recyclerView != null && recyclerView.getVisibility() == View.VISIBLE) - recyclerView.setVisibility(View.GONE); - if (errorTextView.getVisibility() == View.VISIBLE) - errorTextView.setVisibility(View.GONE); - - progressBar.setVisibility(View.VISIBLE); - parseUrl(); - } - } - - private boolean isValidUrl() { - String url = textInputEditText.getText().toString().trim(); - - if (url.isEmpty()) { - textInputEditText.setError(getContext().getString(R.string.add_feed_empty_field)); - return false; - } else if (!Patterns.WEB_URL.matcher(url).matches()) { - textInputEditText.setError(getContext().getString(R.string.add_feed_wrong_url)); - return false; - } else - return true; - } - - private void parseUrl() { - String url = textInputEditText.getText().toString().trim(); - - final String finalUrl; - if (!(url.contains(Utils.HTTP_PREFIX) || url.contains(Utils.HTTPS_PREFIX))) - finalUrl = Utils.HTTPS_PREFIX + url; - else - finalUrl = url; - - Handler handler = new Handler(Looper.getMainLooper()); - - Executors.newSingleThreadExecutor().execute(() -> { - try { - RSSQuery rssApi = new RSSQuery(); - if (rssApi.isUrlFeedLink(finalUrl)) { - ParsingResult parsingResult = new ParsingResult(finalUrl, null); - handler.post(() -> ((MainActivity) getOwnerActivity()).insertNewFeed(parsingResult)); - dismiss(); - } else { - List results = HtmlParser.getFeedLink(finalUrl); - - if (results.size() > 0) - handler.post(() -> displayResults(results)); - else - handler.post(() -> displayError(R.string.add_feed_no_result)); - } - } catch (Exception e) { - if (e instanceof UnknownHostException) - handler.post(() -> displayError(R.string.add_feed_unknownhost_error)); - else - handler.post(() -> displayError(R.string.add_feed_connexion_error)); - } - - - }); - } - - private void displayResults(List results) { - recyclerView = findViewById(R.id.add_feed_recyclerview); - adapter = new AddFeedListAdapter(results); - - adapter.setOnItemClickListener((parsingResult -> { - ((MainActivity) getOwnerActivity()).insertNewFeed(parsingResult); - dismiss(); - })); - - RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); - recyclerView.setLayoutManager(layoutManager); - DividerItemDecoration decoration = new DividerItemDecoration(getContext(), ((LinearLayoutManager) layoutManager).getOrientation()); - recyclerView.addItemDecoration(decoration); - - recyclerView.setAdapter(adapter); - progressBar.setVisibility(View.GONE); - recyclerView.setVisibility(View.VISIBLE); - } - - private void displayError(@StringRes int stringId) { - progressBar.setVisibility(View.GONE); - errorTextView.setVisibility(View.VISIBLE); - errorTextView.setText(stringId); - } -} diff --git a/app/src/main/java/com/readrops/app/views/AddFeedListAdapter.java b/app/src/main/java/com/readrops/app/views/AddFeedListAdapter.java deleted file mode 100644 index 6b122583..00000000 --- a/app/src/main/java/com/readrops/app/views/AddFeedListAdapter.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.readrops.app.views; - -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.readrops.app.R; -import com.readrops.app.utils.ParsingResult; - -import java.util.List; - -public class AddFeedListAdapter extends RecyclerView.Adapter { - - private List results; - private OnItemClickListener listener; - - public AddFeedListAdapter(List results) { - this.results = results; - } - - @NonNull - @Override - public AddFeedViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { - View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.add_feed_item, viewGroup, false); - - return new AddFeedViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull AddFeedViewHolder addFeedViewHolder, int i) { - addFeedViewHolder.bind(results.get(i)); - - } - - @Override - public int getItemCount() { - return results.size(); - } - - public interface OnItemClickListener { - void onItemClick(ParsingResult parsingResult); - } - - public void setOnItemClickListener(OnItemClickListener listener) { - this.listener = listener; - } - - - public class AddFeedViewHolder extends RecyclerView.ViewHolder { - - private TextView label; - private TextView url; - - public AddFeedViewHolder(@NonNull View itemView) { - super(itemView); - - itemView.setOnClickListener((view) -> { - int position = getAdapterPosition(); - if (listener != null && position != RecyclerView.NO_POSITION) - listener.onItemClick(results.get(position)); - }); - - label = itemView.findViewById(R.id.add_feed_item_label); - url = itemView.findViewById(R.id.add_feed_item_url); - } - - public void bind(ParsingResult parsingResult) { - label.setText(parsingResult.getLabel()); - url.setText(parsingResult.getUrl()); - } - } -} diff --git a/app/src/main/java/com/readrops/app/views/SimpleCallback.java b/app/src/main/java/com/readrops/app/views/SimpleCallback.java deleted file mode 100644 index 6afae24f..00000000 --- a/app/src/main/java/com/readrops/app/views/SimpleCallback.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.readrops.app.views; - -public interface SimpleCallback { - - void onSuccess(); - - void onFailure(Exception e); -}