ActionBar, Menu, Logout

ActionBar hinzugefügt
Menu zu ActionBar hinzugefügt
Logout jetzt in Actionbar
This commit is contained in:
Georg Reisinger 2019-01-26 20:00:38 +01:00
parent 071f6b9be2
commit 36bc515c4b
6 changed files with 53 additions and 63 deletions

View File

@ -19,8 +19,8 @@
</activity>
<activity
android:name=".Dash"
android:label="@string/title_activity_dash"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:label="SmartShopper"
android:theme="@style/AppTheme"></activity>
</application>
</manifest>

View File

@ -1,13 +1,20 @@
package at.smartshopper.smartshopper;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
@ -29,10 +36,7 @@ public class Dash extends AppCompatActivity {
private Database db = new Database();
private SwipeRefreshLayout ownswiperefresh;
private void goLogin() {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
@Override
@ -41,20 +45,12 @@ public class Dash extends AppCompatActivity {
setContentView(R.layout.activity_dash);
// Erstellt die Tabs
tabHoster();
Button logoutBtn = (Button) findViewById(R.id.logoutBtn);
logoutBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
goLogin();
}
});
/*
Get userinformations
Get userinformations and show them
*/
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
@ -92,11 +88,21 @@ public class Dash extends AppCompatActivity {
}
}
/**
* Logt den User aus und geht zur Login Activity
*/
private void logout(){
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
/**
* Refreshed die eigene shoppinglist und veranlasst das das refreshen beendet wird
*
* @param uid Von dem benutzer von welchem die Shoppinglists angezeigt werden sollen
*/
private void refreshOwnShoppinglist(String uid){
private void refreshOwnShoppinglist(String uid) {
try {
showOwnShoppingList(uid);
} catch (JSONException e) {
@ -152,31 +158,30 @@ public class Dash extends AppCompatActivity {
host.addTab(spec);
}
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
getMenuInflater().inflate(R.menu.dash_menu, 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();
switch (item.getItemId()) {
case R.id.logoutBtn:
logout();
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
*/
}

View File

@ -9,9 +9,7 @@
<TabHost
android:id="@+id/tabHost1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
@ -21,12 +19,14 @@
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent">x
<LinearLayout
android:id="@+id/tab1"
@ -40,14 +40,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/logoutBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ownSwipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -75,12 +68,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/logoutBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/sharedrecycler"
android:layout_width="match_parent"
@ -91,6 +78,7 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/logoutBtn"
android:title="Logout"
android:enabled="true" />
</menu>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimary">#FFFFFF</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#880e4f</color>
</resources>

View File

@ -1,20 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
</resources>