Commit 8409fa90 authored by Varun Patil's avatar Varun Patil

Reduce technical debt (1)

parent 3735fc4f
......@@ -74,7 +74,7 @@ public class MessMenuAdapter extends RecyclerView.Adapter<MessMenuAdapter.ViewHo
case 7:
return "Sunday";
default:
throw new RuntimeException("DayIndexOutOfBounds: " + day);
throw new IndexOutOfBoundsException("DayIndexOutOfBounds: " + day);
}
}
......
......@@ -29,7 +29,6 @@ public class NewsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
private final int VIEW_PROG = 0;
private List<NewsArticle> newsArticles;
private Context context;
private ItemClickListener itemClickListener;
public NewsAdapter(List<NewsArticle> newsArticles, ItemClickListener itemClickListener) {
......@@ -51,7 +50,7 @@ public class NewsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> i
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
context = parent.getContext();
final Context context = parent.getContext();
if (viewType == VIEW_ITEM) {
LayoutInflater inflater = LayoutInflater.from(context);
View postView = inflater.inflate(R.layout.news_article_card, parent, false);
......
......@@ -27,7 +27,6 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<RecyclerView.View
private final int VIEW_ITEM = 1;
private final int VIEW_PROG = 0;
private List<PlacementBlogPost> posts;
private Context context;
private ItemClickListener itemClickListener;
public PlacementBlogAdapter(List<PlacementBlogPost> posts, ItemClickListener itemClickListener) {
this.posts = posts;
......@@ -45,7 +44,7 @@ public class PlacementBlogAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
context = parent.getContext();
final Context context = parent.getContext();
if (viewType == VIEW_ITEM) {
LayoutInflater inflater = LayoutInflater.from(context);
View postView = inflater.inflate(R.layout.blog_post_card, parent, false);
......
......@@ -18,9 +18,10 @@ import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ServiceGenerator {
public static final String HEADER_CACHE_CONTROL = "Cache-Control";
public static final String HEADER_PRAGMA = "Pragma";
private static final String HEADER_CACHE_CONTROL = "Cache-Control";
private static final String HEADER_PRAGMA = "Pragma";
private static final String BASE_URL = "https://api.insti.app/api/";
public RetrofitInterface retrofitInterface;
private Context context;
......@@ -99,10 +100,9 @@ public class ServiceGenerator {
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create());
private Retrofit retrofit;
public RetrofitInterface retrofitInterface;
public ServiceGenerator(Context mContext) {
context = mContext;
final Retrofit retrofit;
retrofit = retrofitBuilder.client(
clientBuilder
.addInterceptor(provideOfflineCacheInterceptor)
......
package app.insti.api;
import android.content.Context;
import java.security.cert.CertificateException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient(Context context) {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
Cache cache = new Cache(context.getCacheDir(), 200000000);
builder.cache(cache);
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
......@@ -136,7 +136,7 @@ public class AddEventFragment extends BaseFragment {
return view;
}
void openEvent(Event event) {
private void openEvent(Event event) {
String eventJson = new Gson().toJson(event);
Bundle bundle = getArguments();
if (bundle == null)
......@@ -151,7 +151,7 @@ public class AddEventFragment extends BaseFragment {
transaction.addToBackStack(eventFragment.getTag()).commit();
}
void openBody(Body body) {
private void openBody(Body body) {
BodyFragment bodyFragment = BodyFragment.newInstance(body);
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
......
......@@ -110,8 +110,6 @@ public class MapFragment extends Fragment implements TextWatcher,
public static final int SOUND_ID_RESULT = 0;
public static final int SOUND_ID_ADD = 1;
public static final int SOUND_ID_REMOVE = 2;
private static final String INSTANCE_CARD_STATE = "instanceCardState";
private static final String INSTANCE_VISIBILITY_INDEX = "instanceVisibilityIndex";
private static MapFragment mainactivity;
private final String firstStackTag = "FIRST_TAG";
private final int MSG_ANIMATE = 1;
......@@ -137,10 +135,7 @@ public class MapFragment extends Fragment implements TextWatcher,
private ListFragment listFragment;
private Fragment fragment;
private RelativeLayout fragmentContainer;
private View actionBarView;
private List<com.mrane.data.Marker> markerlist;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private SlidingUpPanelLayout slidingLayout;
private CardSlideListener cardSlideListener;
private boolean noFragments = true;
......@@ -363,22 +358,6 @@ public class MapFragment extends Fragment implements TextWatcher,
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void initShowDefault() {
String[] keys = {"Convocation Hall", "Hostel 13 House of Titans",
"Hostel 15", "Main Gate no. 2",
......@@ -426,12 +405,8 @@ public class MapFragment extends Fragment implements TextWatcher,
Runnable runnable = new Runnable() {
@Override
public void run() {
int totalHeight = slidingLayout.getHeight();
int expandedCardHeight = getResources().getDimensionPixelSize(
R.dimen.expanded_card_height);
float anchorPoint = 0.5f;
slidingLayout.setAnchorPoint(anchorPoint);
Log.d("testing", "Anchor point = " + anchorPoint);
}
};
......@@ -703,12 +678,12 @@ public class MapFragment extends Fragment implements TextWatcher,
if (marker instanceof Room) {
Room room = (Room) marker;
String tag = room.tag;
if (!tag.equals("Inside")) {
if (!"Inside".equals(tag)) {
tag += ",";
} else {
tag = "in";
}
com.mrane.data.Marker parent = data.get(room.parentKey);
Marker parent = data.get(room.parentKey);
final String parentKey = parent.getName();
String parentName = parent.getName();
if (!parent.getShortName().equals("0"))
......@@ -899,11 +874,7 @@ public class MapFragment extends Fragment implements TextWatcher,
private boolean handleRemoveIcon() {
String text = editText.getText().toString();
if (text.isEmpty() || text.equals(null)) {
return false;
} else {
return true;
}
return !text.isEmpty();
}
@Override
......
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