Skip to content

Commit

Permalink
feat(design): update design with drawer and toolbar
Browse files Browse the repository at this point in the history
Signed-off-by: Rafa Hernandez <[email protected]>
rafaelje authored and ajsb85 committed Mar 26, 2018
1 parent 1a780c9 commit 4364b4c
Showing 1 changed file with 98 additions and 24 deletions.
122 changes: 98 additions & 24 deletions app/src/main/java/org/flyve/inventory/agent/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package org.flyve.inventory.agent;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
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.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import org.flyve.inventory.agent.adapter.DrawerAdapter;
import org.flyve.inventory.agent.utils.FlyveLog;

import java.util.ArrayList;
import java.util.HashMap;

/*
* Copyright © 2017 Teclib. All rights reserved.
*
@@ -38,37 +46,103 @@

public class MainActivity extends AppCompatActivity {

public static final String FLAG_COMMIT_FRAGMENT = "commitFragment";
private ProgressDialog pd;

private DrawerLayout mDrawerLayout;
private FragmentManager mFragmentManager;
private ListView lstDrawer;
private ArrayList<HashMap<String, String>> arrDrawer;
private HashMap<String, String> selectedItem;
private TextView txtToolbarTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = findViewById(R.id.toolbar);
// Setup the DrawerLayout and NavigationView
txtToolbarTitle = findViewById(R.id.txtToolbarTitle);
mDrawerLayout = findViewById(R.id.drawerLayout);

lstDrawer = findViewById(R.id.lstNV);
lstDrawer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mDrawerLayout.closeDrawers();
selectedItem = arrDrawer.get(position);
loadFragment(selectedItem);
}
});

mFragmentManager = getSupportFragmentManager();

// Setup Drawer Toggle of the Toolbar
android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);

mDrawerLayout.setDrawerListener(mDrawerToggle);

mDrawerToggle.syncState();

loadListDrawer();

try {
toolbar.setTitle(getResources().getString(R.string.app_name));
setSupportActionBar(toolbar);
getSupportActionBar().setIcon(R.drawable.icon);
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}
}

public static Intent getStartIntent(Context context, boolean commitFragment) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(FLAG_COMMIT_FRAGMENT, commitFragment);
return intent;
/**
* Loads the Fragment
* @param item
*/
private void loadFragment(HashMap<String, String> item) {

FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

txtToolbarTitle.setText(item.get("name").toUpperCase());

// Home
if (item.get("id").equals("1")) {
FragmentHome f = new FragmentHome();
fragmentTransaction.replace(R.id.containerView, f).commit();
return;
}
}

public void loading(Boolean visible) {
if(visible) {
pd = ProgressDialog.show(MainActivity.this, "", getResources().getString(R.string.loading));
} else {
pd.dismiss();
/**
* Load the list drawer
*/
public void loadListDrawer() {

arrDrawer = new ArrayList<>();

// Information
HashMap<String, String> map = new HashMap<>();
map.put("id", "1");
map.put("name", getResources().getString(R.string.drawer_inventory));
map.put("img", "ic_info");
arrDrawer.add(map);

// Help
map = new HashMap<>();
map.put("id", "4");
map.put("name", getResources().getString(R.string.drawer_help));
map.put("img", "ic_help");
arrDrawer.add(map);

// About
map = new HashMap<>();
map.put("id", "5");
map.put("name", getResources().getString(R.string.drawer_about));
map.put("img", "ic_about");
arrDrawer.add(map);

try {
// lad adapter
DrawerAdapter adapter = new DrawerAdapter(this, arrDrawer);
lstDrawer.setAdapter(adapter);

// Select Information on load //
selectedItem = arrDrawer.get(0);
loadFragment(selectedItem);
} catch(Exception ex) {
FlyveLog.e(ex.getMessage());
}
}
}

0 comments on commit 4364b4c

Please sign in to comment.