Browse Source

working on fragment layout for votes page

pull/2/head
Yiğit Çolakoğlu 6 years ago
parent
commit
056ed73107
19 changed files with 287 additions and 42 deletions
  1. +2
    -0
      MyCity/app/build.gradle
  2. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java
  3. +17
    -17
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  4. +73
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/vote/MyVotesRecyclerViewAdapter.java
  5. +1
    -1
      MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesActivity.java
  6. +48
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesContent.java
  7. +86
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesFragment.java
  8. +0
    -0
      MyCity/app/src/main/res/drawable-v21/bus.xml
  9. +0
    -0
      MyCity/app/src/main/res/drawable-v21/navigation.xml
  10. +0
    -0
      MyCity/app/src/main/res/drawable-v21/parking.xml
  11. +0
    -0
      MyCity/app/src/main/res/drawable-v21/star.xml
  12. +0
    -0
      MyCity/app/src/main/res/drawable-v21/utility.xml
  13. +0
    -0
      MyCity/app/src/main/res/drawable-v21/vote.xml
  14. +12
    -0
      MyCity/app/src/main/res/drawable/vote_style.xml
  15. +1
    -9
      MyCity/app/src/main/res/layout/app_bar_main.xml
  16. +29
    -0
      MyCity/app/src/main/res/layout/fragment_votes.xml
  17. +16
    -0
      MyCity/app/src/main/res/layout/fragment_votes_list.xml
  18. +0
    -14
      MyCity/app/src/main/res/layout/voting_content.xml
  19. +1
    -0
      MyCity/app/src/main/res/values/dimens.xml

+ 2
- 0
MyCity/app/build.gradle View File

@ -25,6 +25,8 @@ dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


MyCity/app/src/main/java/gq/yigit/mycity/fileActions.java → MyCity/app/src/main/java/gq/yigit/mycity/FileActions.java View File


+ 17
- 17
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -3,11 +3,11 @@ package gq.yigit.mycity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.*;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
@ -16,13 +16,11 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ViewFlipper;
import java.io.*;
import gq.yigit.mycity.vote.VotesContent;
import gq.yigit.mycity.vote.VotesFragment;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
implements NavigationView.OnNavigationItemSelectedListener, VotesFragment.OnListFragmentInteractionListener {
public Context cntxt;
@ -71,9 +69,7 @@ public class MainActivity extends AppCompatActivity
@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
@ -86,7 +82,7 @@ public class MainActivity extends AppCompatActivity
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
fileActions file_manager = new fileActions();
FileActions file_manager = new FileActions();
file_manager.writeToFile(input.getText().toString(),cntxt,"serverip.config");
}
});
@ -109,14 +105,14 @@ public class MainActivity extends AppCompatActivity
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (id == R.id.voting) {
ViewFlipper vf = (ViewFlipper)findViewById(R.id.page);
try {
vf.setDisplayedChild(1);
}catch (Exception e){
Log.e("[ERROR]",e.toString());
}
VotesFragment fragment = new VotesFragment();
fragmentTransaction.add(R.id.app_bar_main, fragment);
fragmentTransaction.commit();
} else if (id == R.id.parking) {
} else if (id == R.id.transit) {
@ -134,4 +130,8 @@ public class MainActivity extends AppCompatActivity
return true;
}
public void onListFragmentInteraction(VotesContent.VoteItem vote){
}
}

+ 73
- 0
MyCity/app/src/main/java/gq/yigit/mycity/vote/MyVotesRecyclerViewAdapter.java View File

@ -0,0 +1,73 @@
package gq.yigit.mycity.vote;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import gq.yigit.mycity.R;
import gq.yigit.mycity.vote.VotesFragment.OnListFragmentInteractionListener;
import gq.yigit.mycity.vote.VotesContent.VoteItem;
import java.util.List;
public class MyVotesRecyclerViewAdapter extends RecyclerView.Adapter<MyVotesRecyclerViewAdapter.ViewHolder> {
private final List<VoteItem> mValues;
private final OnListFragmentInteractionListener mListener;
public MyVotesRecyclerViewAdapter(List<VoteItem> items, OnListFragmentInteractionListener listener) {
mValues = items;
mListener = listener;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_votes, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
holder.mIdView.setText(mValues.get(position).name);
holder.mContentView.setText(mValues.get(position).details);
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != mListener) {
mListener.onListFragmentInteraction(holder.mItem);
}
}
});
}
@Override
public int getItemCount() {
return mValues.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mIdView;
public final TextView mContentView;
public VoteItem mItem;
public ViewHolder(View view) {
super(view);
mView = view;
mIdView = (TextView) view.findViewById(R.id.item_number);
mContentView = (TextView) view.findViewById(R.id.content);
}
@Override
public String toString() {
return super.toString() + " '" + mContentView.getText() + "'";
}
}
}

MyCity/app/src/main/java/gq/yigit/mycity/VotesActivity.java → MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesActivity.java View File


+ 48
- 0
MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesContent.java View File

@ -0,0 +1,48 @@
package gq.yigit.mycity.vote;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class VotesContent {
public static final List<VoteItem> ITEMS = new ArrayList<VoteItem>();
public static final Map<String, VoteItem> ITEM_MAP = new HashMap<String, VoteItem>();
private static void addItem(VoteItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
private static VoteItem creaVoteItem(int position) {
return new VoteItem(String.valueOf(position), "Item " + position, makeDetails(position));
}
private static String makeDetails(int position) {
StringBuilder builder = new StringBuilder();
builder.append("Details about Item: ").append(position);
for (int i = 0; i < position; i++) {
builder.append("\nMore details information here.");
}
return builder.toString();
}
public static class VoteItem {
public final String id;
public final String name;
public final String details;
public VoteItem(String id, String name, String details) {
this.id = id;
this.name = name;
this.details = details;
}
@Override
public String toString() {
return name;
}
}
}

+ 86
- 0
MyCity/app/src/main/java/gq/yigit/mycity/vote/VotesFragment.java View File

@ -0,0 +1,86 @@
package gq.yigit.mycity.vote;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import gq.yigit.mycity.FileActions;
import gq.yigit.mycity.R;
import gq.yigit.mycity.vote.VotesContent.VoteItem;
public class VotesFragment extends Fragment {
private static final String ARG_COLUMN_COUNT = "column-count";
private int mColumnCount = 1;
private OnListFragmentInteractionListener mListener;
public VotesFragment() {
}
public static VotesFragment newInstance(int columnCount) {
VotesFragment fragment = new VotesFragment();
Bundle args = new Bundle();
args.putInt(ARG_COLUMN_COUNT, columnCount);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_votes_list, container, false);
// Set the adapter
if (view instanceof RecyclerView) {
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
if (mColumnCount <= 1) {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
}
FileActions file_manager = new FileActions();
recyclerView.setAdapter(new MyVotesRecyclerViewAdapter(VotesContent.ITEMS, mListener));
}
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnListFragmentInteractionListener {
void onListFragmentInteraction(VoteItem item);
}
}

MyCity/app/src/main/res/drawable/bus.xml → MyCity/app/src/main/res/drawable-v21/bus.xml View File


MyCity/app/src/main/res/drawable/navigation.xml → MyCity/app/src/main/res/drawable-v21/navigation.xml View File


MyCity/app/src/main/res/drawable/parking.xml → MyCity/app/src/main/res/drawable-v21/parking.xml View File


MyCity/app/src/main/res/drawable/star.xml → MyCity/app/src/main/res/drawable-v21/star.xml View File


MyCity/app/src/main/res/drawable/utility.xml → MyCity/app/src/main/res/drawable-v21/utility.xml View File


MyCity/app/src/main/res/drawable/vote.xml → MyCity/app/src/main/res/drawable-v21/vote.xml View File


+ 12
- 0
MyCity/app/src/main/res/drawable/vote_style.xml View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<stroke
android:width="1dp"
android:color="@android:color/black" />
</shape>

+ 1
- 9
MyCity/app/src/main/res/layout/app_bar_main.xml View File

@ -5,6 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/app_bar_main"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
@ -20,15 +21,6 @@
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/page"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include android:id="@+id/include1" layout="@layout/voting_content" />
</ViewFlipper>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"


+ 29
- 0
MyCity/app/src/main/res/layout/fragment_votes.xml View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/vote_style">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@mipmap/ic_launcher" android:id="@+id/imageView2"
android:layout_weight="1"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="1">
<TextView
android:id="@+id/item_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem"/>
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem"/>
</LinearLayout>
</LinearLayout>

+ 16
- 0
MyCity/app/src/main/res/layout/fragment_votes_list.xml View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name="gq.yigit.mycity.VotesFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".vote.VotesFragment"
tools:listitem="@layout/fragment_votes"
android:divider="@android:color/transparent"
android:dividerHeight="10.0sp"/>

+ 0
- 14
MyCity/app/src/main/res/layout/voting_content.xml View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bonjour!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>

+ 1
- 0
MyCity/app/src/main/res/values/dimens.xml View File

@ -5,4 +5,5 @@
<dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="text_margin">16dp</dimen>
</resources>

Loading…
Cancel
Save