Instantly share code, notes, and snippets.
Created
March 20, 2017 23:09
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save achatina/18db71b9503a8e23a48300fba5af3a86 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import android.content.Context; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.util.List; | |
public class AdapterMenu extends RecyclerView.Adapter<AdapterMenu.MyRecycler> { | |
private Context context; | |
private List<MenuList> items; | |
public AdapterMenu(Context context, List<MenuList> items){ | |
this.context = context; | |
this.items = items; | |
} | |
@Override | |
public MyRecycler onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(context) | |
.inflate(R.layout.menu_list, null); | |
return new MyRecycler(view); | |
} | |
@Override | |
public void onBindViewHolder(MyRecycler holder, int position) { | |
holder.name.setText(items.get(position).getNameOfDish()); | |
holder.price.setText(items.get(position).getPriceOfDish()); | |
holder.recept.setText(items.get(position).getRecept()); | |
holder.photo.setImageResource(items.get(position).getIdPhotoOfDish()); | |
} | |
@Override | |
public int getItemCount() { | |
return items.size(); | |
} | |
class MyRecycler extends RecyclerView.ViewHolder{ | |
TextView name; | |
TextView recept; | |
TextView price; | |
ImageView photo; | |
public MyRecycler(View itemView) { | |
super(itemView); | |
name = (TextView)itemView.findViewById(R.id.nameOfDish); | |
recept = (TextView)itemView.findViewById(R.id.recept); | |
price = (TextView)itemView.findViewById(R.id.price); | |
photo = (ImageView) itemView.findViewById(R.id.photoOfDish); | |
} | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import android.content.Context; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.runner.AndroidJUnit4; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static org.junit.Assert.*; | |
/** | |
* Instrumentation test, which will execute on an Android device. | |
* | |
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |
*/ | |
@RunWith(AndroidJUnit4.class) | |
public class ExampleInstrumentedTest { | |
@Test | |
public void useAppContext() throws Exception { | |
// Context of the app under test. | |
Context appContext = InstrumentationRegistry.getTargetContext(); | |
assertEquals("com.nicksapp.menureserv", appContext.getPackageName()); | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
/** | |
* Example local unit test, which will execute on the development machine (host). | |
* | |
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |
*/ | |
public class ExampleUnitTest { | |
@Test | |
public void addition_isCorrect() throws Exception { | |
assertEquals(4, 2 + 2); | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import android.app.Fragment; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.util.AttributeSet; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class FragmentMenu extends Fragment { | |
ImageView pic; | |
TextView name; | |
TextView recept; | |
TextView price; | |
AdapterMenu adapter; | |
RecyclerView recyclerView; | |
Context context; | |
List<MenuList> items = new ArrayList<>(); | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment, null); | |
recyclerView = (RecyclerView)view.findViewById(R.id.recycler); | |
context = getActivity(); | |
initList(); | |
LinearLayoutManager linearLayoutManager | |
= new LinearLayoutManager(getActivity(), | |
LinearLayoutManager.VERTICAL, | |
false); | |
recyclerView.setLayoutManager(linearLayoutManager); | |
recyclerView = new RecyclerView(context, (AttributeSet) items); | |
recyclerView.setAdapter(adapter); | |
return view; | |
} | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
pic = (ImageView)view.findViewById(R.id.photoOfDish); | |
name = (TextView)view.findViewById(R.id.nameOfDish); | |
recept = (TextView)view.findViewById(R.id.recept); | |
price = (TextView)view.findViewById(R.id.price); | |
} | |
private void initList(){ | |
int image = R.mipmap.ic_launcher; | |
items.add(new MenuList( | |
"Борщ", | |
"13,50", | |
"Мясо, вода и всё такое.", | |
image | |
)); | |
items.add(new MenuList( | |
"Борщ", | |
"13,50", | |
"Мясо, вода и всё такое.", | |
image | |
)); | |
items.add(new MenuList( | |
"Борщ", | |
"13,50", | |
"Мясо, вода и всё такое.", | |
image | |
)); | |
items.add(new MenuList( | |
"Борщ", | |
"13,50", | |
"Мясо, вода и всё такое.", | |
image | |
)); | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.design.widget.NavigationView; | |
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.view.Menu; | |
import android.view.MenuItem; | |
public class MainActivity extends AppCompatActivity | |
implements NavigationView.OnNavigationItemSelectedListener { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
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); | |
} | |
@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.menu) { | |
getFragmentManager().beginTransaction() | |
.add(R.id.fragment, new FragmentMenu()) | |
.commit(); | |
} else if (id == R.id.reserv) { | |
Intent intent = new Intent(this, ReservActivity.class); | |
startActivity(intent); | |
} else if (id == R.id.map_find) { | |
} | |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); | |
drawer.closeDrawer(GravityCompat.START); | |
return true; | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
/** | |
* Created by neket on 13.03.2017. | |
*/ | |
public class MenuList { | |
private String nameOfDish; | |
private String priceOfDish; | |
private String recept; | |
private int idPhotoOfDish; | |
public MenuList(String nameOfDish, String priceOfDish, String recept, int idPhotoOfDish){ | |
this.idPhotoOfDish = idPhotoOfDish; | |
this.nameOfDish = nameOfDish; | |
this.priceOfDish = priceOfDish; | |
this.recept = recept; | |
} | |
public String getNameOfDish() { | |
return nameOfDish; | |
} | |
public void setNameOfDish(String nameOfDish) { | |
this.nameOfDish = nameOfDish; | |
} | |
public String getPriceOfDish() { | |
return priceOfDish; | |
} | |
public void setPriceOfDish(String priceOfDish) { | |
this.priceOfDish = priceOfDish; | |
} | |
public String getRecept() { | |
return recept; | |
} | |
public void setRecept(String recept) { | |
this.recept = recept; | |
} | |
public int getIdPhotoOfDish() { | |
return idPhotoOfDish; | |
} | |
public void setIdPhotoOfDish(int idPhotoOfDish) { | |
this.idPhotoOfDish = idPhotoOfDish; | |
} | |
} |
This file contains hidden or 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
package com.nicksapp.menureserv; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
public class ReservActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_reserv); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment