-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
799821e
commit a2d1764
Showing
24 changed files
with
450 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 141 additions & 8 deletions
149
app/src/main/java/com/pulkit4tech/privy/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,159 @@ | ||
package com.pulkit4tech.privy; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.content.pm.PackageManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.NavigationView; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.app.Fragment; | ||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v4.view.GravityCompat; | ||
import android.support.v4.widget.DrawerLayout; | ||
import android.support.v7.app.ActionBarDrawerToggle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.pulkit4tech.privy.fragments.PrivyMapsFragment; | ||
import com.pulkit4tech.privy.utilities.NoLocationPermission; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
import static com.pulkit4tech.privy.constants.Constants.DEBUG; | ||
import static com.pulkit4tech.privy.constants.Constants.MY_PERMISSIONS_REQUEST_FINE_LOCATIONS; | ||
|
||
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
if(savedInstanceState == null){ | ||
// calling PrivyMapsActivity | ||
Intent intent = new Intent(this,PrivyMapsActivity.class); | ||
startActivity(intent); | ||
if (savedInstanceState == null) { | ||
setUpInfo(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
} | ||
|
||
private void setUpInfo() { | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
|
||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | ||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( | ||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); | ||
drawer.setDrawerListener(toggle); | ||
toggle.syncState(); | ||
|
||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); | ||
navigationView.setNavigationItemSelectedListener(this); | ||
navigationView.getMenu().getItem(0).setChecked(true); | ||
loadMapFragment(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
this.finish(); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
switch (requestCode) { | ||
case MY_PERMISSIONS_REQUEST_FINE_LOCATIONS: | ||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
Toast.makeText(this, "Permission granted!!", Toast.LENGTH_SHORT).show(); | ||
loadFragment(new PrivyMapsFragment()); | ||
} else { | ||
loadFragment(new NoLocationPermission()); | ||
Toast.makeText(this, "Please give permission for location", Toast.LENGTH_SHORT).show(); | ||
} | ||
break; | ||
|
||
default: | ||
Log.d(DEBUG, "Some other request code: " + requestCode); | ||
} | ||
} | ||
|
||
private void loadFragment(Fragment fragment) { | ||
getSupportFragmentManager().beginTransaction().add(R.id.frame_container, fragment).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit(); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | ||
if (drawer.isDrawerOpen(GravityCompat.START)) { | ||
drawer.closeDrawer(GravityCompat.START); | ||
} else { | ||
super.onBackPressed(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
|
||
//noinspection SimplifiableIfStatement | ||
if (id == R.id.action_settings) { | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
@SuppressWarnings("StatementWithEmptyBody") | ||
@Override | ||
public boolean onNavigationItemSelected(MenuItem item) { | ||
// Handle navigation view item clicks here. | ||
int id = item.getItemId(); | ||
|
||
if (id == R.id.nav_nearby_privy) { | ||
loadMapFragment(); | ||
} | ||
//TODO : Add other conditions | ||
|
||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | ||
drawer.closeDrawer(GravityCompat.START); | ||
return true; | ||
} | ||
|
||
private void loadMapFragment() { | ||
if (!checkLocationEnabledPermission()) { | ||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_FINE_LOCATIONS); | ||
} else { | ||
loadFragment(new PrivyMapsFragment()); | ||
} | ||
} | ||
|
||
private boolean checkLocationEnabledPermission() { | ||
return ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.