Delete unused code

This commit is contained in:
Shinokuni 2019-03-18 11:05:00 +01:00
parent 3e50e63626
commit ee0e8aa83e
7 changed files with 1 additions and 264 deletions

View File

@ -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 {

View File

@ -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<Feed> sync(List<Feed> 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());
}
}

View File

@ -116,9 +116,8 @@ public class LocalFeedRepository extends ARepository {
insertFeed(queryResult.getFeed(), queryResult.getRssType());
}
postCallBackSuccess();
} catch (Exception e) {
failureCallBackInMainThread(e);
}
});
}

View File

@ -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<Feed> sync(List<Feed> feeds) {
return repository.sync(feeds);
}

View File

@ -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<ParsingResult> 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<ParsingResult> 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);
}
}

View File

@ -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<AddFeedListAdapter.AddFeedViewHolder> {
private List<ParsingResult> results;
private OnItemClickListener listener;
public AddFeedListAdapter(List<ParsingResult> 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());
}
}
}

View File

@ -1,8 +0,0 @@
package com.readrops.app.views;
public interface SimpleCallback {
void onSuccess();
void onFailure(Exception e);
}