Commit ecafd9b9 authored by Varun Patil's avatar Varun Patil

Fix crash on location access

parent 789bde5f
......@@ -2,7 +2,6 @@ package app.insti;
public class Constants {
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
public static final int MY_PERMISSIONS_REQUEST_ACCESS_LOCATION = 2;
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 3;
public static final int RESULT_LOAD_IMAGE = 11;
public static final int REQUEST_CAMERA_INT_ID = 101;
......
......@@ -88,8 +88,8 @@ public final class Utils {
public static final void updateFragment(Fragment fragment, FragmentActivity fragmentActivity) {
FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_up, R.anim.fade_out, R.anim.fade_in, R.anim.slide_out_down);
ft.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag());
ft.addToBackStack(fragment.getTag());
ft.replace(R.id.framelayout_for_fragment, fragment, getTag(fragment));
ft.addToBackStack(getTag(fragment));
ft.commit();
}
......@@ -141,8 +141,8 @@ public final class Utils {
}
/* Update the fragment */
ft.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag())
.addToBackStack(fragment.getTag())
ft.replace(R.id.framelayout_for_fragment, fragment, getTag(fragment))
.addToBackStack(getTag(fragment))
.commit();
}
......@@ -247,8 +247,8 @@ public final class Utils {
FragmentManager fm = fragmentActivity.getSupportFragmentManager();
fm.popBackStack();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(newFragment.getTag());
ft.replace(R.id.framelayout_for_fragment, newFragment, newFragment.getTag()).commit();
ft.addToBackStack(getTag(fragment));
ft.replace(R.id.framelayout_for_fragment, newFragment, getTag(fragment)).commit();
}
public static void setSelectedMenuItem(Activity activity, int id) {
......@@ -286,4 +286,12 @@ public final class Utils {
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
}
public static String getTag(Fragment fragment) {
String TAG = fragment.getTag();
try {
TAG = (String) fragment.getClass().getField("TAG").get(fragment);
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
return TAG;
}
}
......@@ -85,7 +85,6 @@ import static app.insti.Constants.DATA_TYPE_NEWS;
import static app.insti.Constants.DATA_TYPE_PT;
import static app.insti.Constants.DATA_TYPE_USER;
import static app.insti.Constants.FCM_BUNDLE_NOTIFICATION_ID;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_ACCESS_LOCATION;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_LOCATION;
import static app.insti.Constants.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE;
import static app.insti.Constants.RESULT_LOAD_IMAGE;
......@@ -616,7 +615,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
* Change the active fragment to the supplied one
*/
public void updateFragment(Fragment fragment) {
Log.d(TAG, "updateFragment: " + fragment.toString());
Bundle bundle = fragment.getArguments();
if (bundle == null) {
bundle = new Bundle();
......@@ -642,8 +640,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.setCustomAnimations(R.anim.slide_in_up, R.anim.fade_out, R.anim.fade_in, R.anim.slide_out_down);
}
transaction.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag());
transaction.addToBackStack(fragment.getTag()).commit();
transaction.replace(R.id.framelayout_for_fragment, fragment, Utils.getTag(fragment));
transaction.addToBackStack(Utils.getTag(fragment)).commit();
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
......@@ -655,21 +653,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
return;
case MY_PERMISSIONS_REQUEST_ACCESS_LOCATION:
case MY_PERMISSIONS_REQUEST_LOCATION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Map
MapFragment mapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MapFragment.TAG);
if (mapFragment != null && mapFragment.isVisible()) {
MapFragment.getMainActivity().setupGPS();
} else {
Toast toast = Toast.makeText(MainActivity.this, "Need Permission", Toast.LENGTH_SHORT);
toast.show();
}
break;
case MY_PERMISSIONS_REQUEST_LOCATION:
Log.i(TAG, "Permission request captured");
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "Permission Granted");
// File complaint
FileComplaintFragment fileComplaintFragment = (FileComplaintFragment) getSupportFragmentManager().findFragmentByTag(FileComplaintFragment.TAG);
if (fileComplaintFragment != null && fileComplaintFragment.isVisible()) {
FileComplaintFragment.getMainActivity().getMapReady();
}
} else {
Log.i(TAG, "Permission Cancelled");
Toast toast = Toast.makeText(MainActivity.this, "Need Permission", Toast.LENGTH_SHORT);
toast.show();
}
......
......@@ -51,7 +51,7 @@ public class ComplaintsFragment extends BaseFragment {
FileComplaintFragment fileComplaintFragment = new FileComplaintFragment();
fileComplaintFragment.setArguments(getArguments());
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.framelayout_for_fragment, fileComplaintFragment, fileComplaintFragment.getTag());
fragmentTransaction.replace(R.id.framelayout_for_fragment, fileComplaintFragment, Utils.getTag(fileComplaintFragment));
fragmentTransaction.addToBackStack("Complaint Fragment").commit();
}
});
......
......@@ -69,10 +69,10 @@ import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import app.insti.Constants;
import app.insti.ComplaintDescriptionAutoCompleteTextView;
import app.insti.R;
import app.insti.ComplaintTag;
import app.insti.Constants;
import app.insti.R;
import app.insti.Utils;
import app.insti.activity.MainActivity;
import app.insti.adapter.ImageViewPagerAdapter;
......@@ -95,7 +95,7 @@ import static app.insti.Constants.RESULT_LOAD_IMAGE;
public class FileComplaintFragment extends Fragment {
private static final String TAG = FileComplaintFragment.class.getSimpleName();
public static final String TAG = FileComplaintFragment.class.getSimpleName();
private static FileComplaintFragment mainactivity;
private Button buttonSubmit;
private ComplaintDescriptionAutoCompleteTextView descriptionAutoCompleteTextview;
......
......@@ -6,7 +6,6 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Typeface;
......@@ -27,8 +26,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.SpannableStringBuilder;
......@@ -41,7 +38,6 @@ import android.text.util.Linkify;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
......@@ -103,6 +99,9 @@ import static app.insti.Constants.MY_PERMISSIONS_REQUEST_LOCATION;
public class MapFragment extends Fragment implements TextWatcher,
TextView.OnEditorActionListener, AdapterView.OnItemClickListener, View.OnFocusChangeListener,
View.OnTouchListener, ExpandableListView.OnChildClickListener {
public static final String TAG = MapFragment.class.getSimpleName();
public static final PointF MAP_CENTER = new PointF(2971f, 1744f);
public static final long DURATION_INIT_MAP_ANIM = 500;
public static final String FONT_SEMIBOLD = "rigascreen_bold.ttf";
......@@ -232,6 +231,7 @@ public class MapFragment extends Fragment implements TextWatcher,
@Override
public void onResponse(Call<List<Venue>> call, Response<List<Venue>> response) {
if (response.isSuccessful()) {
if (getActivity() == null || getView() == null) return;
// Setup fade animation for background
int colorFrom = Utils.getAttrColor(getContext(), R.attr.themeColor);
......
......@@ -18,7 +18,6 @@ public class ListFragment extends Fragment {
MapFragment mainActivity;
FuzzySearchAdapter adapter;
HashMap<String, Marker> data;
View rootView;
ListView list;
......
......@@ -412,22 +412,19 @@ public class CampusMapView extends SubsamplingScaleImageView {
for (Marker marker : markerList) {
if (isInView(marker.getPoint())) {
if (isShowPinScale(marker)
&& !(isResultMarker(marker) || addedMarkerList
.contains(marker))) {
if (shouldShowUp(marker))
if (isShowPinScale(marker) &&
!(isResultMarker(marker) || addedMarkerList.contains(marker)) &&
shouldShowUp(marker)) {
drawPionterAndText(canvas, marker);
}
}
}
for (Marker marker : addedMarkerList) {
if (isInView(marker.getPoint())) {
if (!isResultMarker(marker)) {
if (isInView(marker.getPoint()) && !isResultMarker(marker)) {
drawMarkerBitmap(canvas, marker);
drawMarkerText(canvas, marker);
}
}
}
Marker marker = getResultMarker();
if (marker != null) {
if (isInView(marker.getPoint())) {
......@@ -689,8 +686,6 @@ public class CampusMapView extends SubsamplingScaleImageView {
if (motionEvent.getX() < 20 * density) {
getParent().requestDisallowInterceptTouchEvent(false);
return true;
} else {
// CampusMapView.this.setPanEnabled(true);
}
} else if (action == MotionEvent.ACTION_UP) {
CampusMapView.this.setPanEnabled(true);
......
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