Skip to content

Commit

Permalink
Test #5 RecyclerView(Before listView deprecation)
Browse files Browse the repository at this point in the history
  • Loading branch information
f4ded4k committed Feb 9, 2018
1 parent 82771de commit 3d2e5fe
Showing 1 changed file with 20 additions and 86 deletions.
106 changes: 20 additions & 86 deletions app/src/main/java/com/indrajit/myplaces/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.animation.DynamicAnimation;
import android.support.animation.SpringAnimation;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -38,7 +37,6 @@ public class MainActivity extends SQLActivity {
private Snackbar snackbar;
private int global_i;
private boolean expand;
private CountDownTimer timer;
private RecyclerView recyclerView;
private ListView listView;
private LocationAdapter locationAdapter;
Expand Down Expand Up @@ -78,39 +76,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}

@Override
public boolean onContextItemSelected(MenuItem item) {
super.onContextItemSelected(item);

switch(item.getItemId()){
case R.id.itemEdit:
openEditor();
return true;

case R.id.itemDelete:
deleteLocationConfirmation();
return true;

case R.id.itemDirection:
goToDirection();
return true;

case R.id.itemGmap:
goToGmap();
return true;

default:
return false;
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -144,15 +109,16 @@ public void _onClickMenuItems(MenuItem item, int i) {
switch(item.getItemId()){
case R.id.itemEdit:
openEditor();

break;
case R.id.itemDelete:
deleteLocationConfirmation();

deleteLocationConfirmation(i);
break;
case R.id.itemDirection:
goToDirection();

goToDirection(i);
break;
case R.id.itemGmap:
goToGmap();
goToGmap(i);
break;
}
}
}, RecyclerDataFetcher.populateList(this));
Expand All @@ -161,17 +127,6 @@ public void _onClickMenuItems(MenuItem item, int i) {
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(locationAdapter);
expand=false;
timer = new CountDownTimer(210,210) {
@Override
public void onTick(long l) {

}

@Override
public void onFinish() {
extendButton.setClickable(true);
}
};

extendButton = findViewById(R.id.extendButton);
mapButton = findViewById(R.id.mapButton);
Expand Down Expand Up @@ -266,27 +221,24 @@ public void onClick(View view) {
.show();
}

private void deleteLocationConfirmation(){
private void deleteLocationConfirmation(final int i){

new AlertDialog.Builder(this)
.setMessage("Are you sure?")
.setNegativeButton("No", null)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
public void onClick(DialogInterface dialogInterface, int j) {

AlertDialog dialog = showLoader(MainActivity.this, R.layout.activity_delete);
Cursor cursor = database.rawQuery("SELECT lat,lon FROM locations",null);
if(cursor.getCount() > 0){

cursor.moveToPosition(global_i -1);
Object[] params = new Object[]{ cursor.getDouble(0), cursor.getDouble(1)};
locationlist.remove(global_i);
String sql = "DELETE FROM locations WHERE lat=? AND lon=?";
database.execSQL(sql, params);
}
cursor.close();
Object[] params = new Object[]{ LocationAdapter.myLocations.get(i).getLat(), LocationAdapter.myLocations.get(i).getLon()};
locationlist.remove(global_i);
String sql = "DELETE FROM locations WHERE lat=? AND lon=?";
database.execSQL(sql, params);
LocationAdapter.myLocations.remove(i);
locationAdapter.notifyItemRemoved(i);
adapter.notifyDataSetChanged();

dialog.dismiss();
}
})
Expand Down Expand Up @@ -314,18 +266,9 @@ public void onClickMap(View view) {
switchActivity();
}

private void goToDirection() {

double lat = 0, lon = 0;

Cursor cursor = database.rawQuery("SELECT lat,lon FROM locations",null);
if(cursor.getCount() > 0){
private void goToDirection(int i) {

cursor.moveToPosition(global_i -1);
lat = cursor.getDouble(0);
lon = cursor.getDouble(1);
}
cursor.close();
double lat = LocationAdapter.myLocations.get(i).getLat(), lon = LocationAdapter.myLocations.get(i).getLon();

String str = "https://www.google.com/maps/dir/?api=1&" + "&destination=" + String.valueOf(lat) + "," + String.valueOf(lon);

Expand All @@ -334,18 +277,9 @@ private void goToDirection() {

}

private void goToGmap(){

double lat = 0, lon = 0;
private void goToGmap(int i){

Cursor cursor = database.rawQuery("SELECT lat,lon FROM locations",null);
if(cursor.getCount() > 0){

cursor.moveToPosition(global_i -1);
lat = cursor.getDouble(0);
lon = cursor.getDouble(1);
}
cursor.close();
double lat = LocationAdapter.myLocations.get(i).getLat(), lon = LocationAdapter.myLocations.get(i).getLon();

String str = "https://www.google.com/maps/search/?api=1" + "&query=" + String.valueOf(lat) + "," + String.valueOf(lon);

Expand Down

0 comments on commit 3d2e5fe

Please sign in to comment.