Commit 347f9d6d authored by Sajal's avatar Sajal

Move ClickListener outside RecyclerViewFragment for non-browsable items

parent eb245a15
package app.insti;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
......@@ -97,4 +100,9 @@ public final class Utils {
public static void setRetrofitInterface(RetrofitInterface retrofitInterface) {
Utils.retrofitInterface = retrofitInterface;
}
public static void openWebURL(Context context, String URL) {
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
context.startActivity(browse);
}
}
package app.insti.api.model;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
import app.insti.interfaces.Browsable;
import app.insti.Utils;
import app.insti.interfaces.Clickable;
public class NewsArticle implements Browsable {
import static app.insti.Utils.openWebURL;
public class NewsArticle implements Clickable {
@NonNull()
@SerializedName("id")
private String articleID;
......@@ -84,4 +89,16 @@ public class NewsArticle implements Browsable {
public void setBody(Body body) {
this.body = body;
}
@Override
public View.OnClickListener getOnClickListener(final Context context) {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (link != null && !link.isEmpty()) {
openWebURL(context, link);
}
}
};
}
}
package app.insti.api.model;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
import app.insti.interfaces.Browsable;
import app.insti.Utils;
import app.insti.interfaces.Clickable;
public class PlacementBlogPost implements Browsable {
import static app.insti.Utils.openWebURL;
public class PlacementBlogPost implements Clickable {
@NonNull()
@SerializedName("id")
private String postID;
......@@ -72,4 +77,16 @@ public class PlacementBlogPost implements Browsable {
public void setPublished(Timestamp published) {
this.published = published;
}
@Override
public View.OnClickListener getOnClickListener(final Context context) {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (link != null && !link.isEmpty()) {
openWebURL(context, link);
}
}
};
}
}
package app.insti.api.model;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
import app.insti.interfaces.Browsable;
import app.insti.Utils;
import app.insti.interfaces.Clickable;
public class TrainingBlogPost implements Browsable {
import static app.insti.Utils.openWebURL;
public class TrainingBlogPost implements Clickable {
@NonNull()
@SerializedName("id")
private String postID;
......@@ -72,4 +77,16 @@ public class TrainingBlogPost implements Browsable {
public void setPublished(Timestamp published) {
this.published = published;
}
@Override
public View.OnClickListener getOnClickListener(final Context context) {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (link != null && !link.isEmpty()) {
openWebURL(context, link);
}
}
};
}
}
......@@ -22,7 +22,7 @@ import app.insti.R;
import app.insti.Utils;
import app.insti.activity.MainActivity;
import app.insti.api.RetrofitInterface;
import app.insti.interfaces.Browsable;
import app.insti.interfaces.Clickable;
import app.insti.interfaces.ItemClickListener;
import app.insti.interfaces.Readable;
import app.insti.interfaces.Writable;
......@@ -32,7 +32,7 @@ import retrofit2.Response;
import static android.view.View.GONE;
public abstract class RecyclerViewFragment<T extends Browsable, S extends RecyclerView.Adapter<RecyclerView.ViewHolder> & Readable<T> & Writable<T>> extends BaseFragment {
public abstract class RecyclerViewFragment<T extends Clickable, S extends RecyclerView.Adapter<RecyclerView.ViewHolder> & Readable<T> & Writable<T>> extends BaseFragment {
public static boolean showLoader = true;
protected RecyclerView recyclerView;
protected Class<T> postType;
......@@ -103,9 +103,7 @@ public abstract class RecyclerViewFragment<T extends Browsable, S extends Recycl
adapter = adapterType.getDeclaredConstructor(List.class, ItemClickListener.class).newInstance(result, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
String link = result.get(position).getLink();
if (link != null && !link.isEmpty())
openWebURL(link);
result.get(position).getOnClickListener(getContext()).onClick(v);
}
});
initRecyclerView();
......@@ -167,11 +165,6 @@ public abstract class RecyclerViewFragment<T extends Browsable, S extends Recycl
return adapter.getPosts().size();
}
private void openWebURL(String URL) {
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(browse);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_view_menu, menu);
......
package app.insti.interfaces;
public interface Browsable {
String getLink();
}
package app.insti.interfaces;
import android.content.Context;
import android.view.View.OnClickListener;
public interface Clickable {
OnClickListener getOnClickListener(Context context);
}
File mode changed from 100755 to 100644
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment