Skip to content

Commit

Permalink
* add tab layout in table
Browse files Browse the repository at this point in the history
  • Loading branch information
xVemu committed Feb 29, 2020
1 parent 626cbb9 commit 11cbc78
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "pl.vemu.zsme"
minSdkVersion 23
targetSdkVersion 29
versionCode 7
versionName "0.3.2"
versionCode 8
versionName "0.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/pl/vemu/zsme/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class MainActivity extends AppCompatActivity {

private NavController navController;

// TODO save state beetwen fragments
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayoutMediator;

import java.util.List;

import pl.vemu.zsme.databinding.FragmentTableBinding;
Expand Down Expand Up @@ -41,5 +43,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
public void makeAdapter(List<List<Lesson>> lessons) {
binding.viewPager.setAdapter(new TablePageAdapter(this, lessons));
String[] names = {"Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek"};
new TabLayoutMediator(binding.tabLayout, binding.viewPager, (tab, position) -> tab.setText(names[position])).attach();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -20,13 +21,11 @@
public class TableFragmentPage extends Fragment {

private List<Lesson> lessons = new ArrayList<>();
private String day;
private FragmentTablePageBinding binding;

public TableFragmentPage() { }
public TableFragmentPage(List<Lesson> lessons, String day) {
public TableFragmentPage(List<Lesson> lessons) {
this.lessons = lessons;
this.day = day;
}

@Override
Expand All @@ -44,11 +43,10 @@ public void onDestroyView() {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
LinearLayoutManager manager = new LinearLayoutManager(getContext());
binding.recyclerView.setLayoutManager(manager);

binding.day.setText(day);
RecyclerView recyclerView = (RecyclerView) binding.getRoot();
recyclerView.setLayoutManager(manager);

TableAdapter tableAdapter = new TableAdapter(lessons);
binding.recyclerView.setAdapter(tableAdapter);
recyclerView.setAdapter(tableAdapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public TablePageAdapter(@NonNull Fragment fragment, List<List<Lesson>> lessons)
@NonNull
@Override
public Fragment createFragment(int position) {
String[] days = {"Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek"};
return new TableFragmentPage(lessons.get(position), days[position]);
return new TableFragmentPage(lessons.get(position));
}

@Override
Expand Down
21 changes: 18 additions & 3 deletions app/src/main/res/layout/fragment_table.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.viewpager2.widget.ViewPager2 xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".timetableFragment.TableFragment" />
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".timetableFragment.TableFragment">

<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
app:tabMode="auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

</LinearLayout>
22 changes: 2 additions & 20 deletions app/src/main/res/layout/fragment_table_page.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".timetableFragment.TableFragmentPage">

<TextView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
tools:text="@string/title" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</androidx.recyclerview.widget.RecyclerView>

</LinearLayout>
tools:context=".timetableFragment.TableFragmentPage" />
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_timetable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
android:layout_height="0dp"
android:layout_weight="1" />


</LinearLayout>

0 comments on commit 11cbc78

Please sign in to comment.