finished
This commit is contained in:
parent
c129b87b10
commit
a4b29c7bfb
@ -1,2 +1,5 @@
|
|||||||
Name: Paul Lödige
|
Name: Paul Lödige
|
||||||
Matrikel: 15405036
|
Matrikel: 15405036
|
||||||
|
|
||||||
|
Hinweis:
|
||||||
|
Der ViewPager ist im Slideshow-Fragment des NavigationDrawers implementiert
|
||||||
|
@ -37,6 +37,7 @@ dependencies {
|
|||||||
implementation 'androidx.navigation:navigation-ui:2.3.1'
|
implementation 'androidx.navigation:navigation-ui:2.3.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
||||||
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
testImplementation 'junit:junit:4.+'
|
testImplementation 'junit:junit:4.+'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @author Paul Lödige (Matrikel: 15405036)
|
||||||
|
*/
|
||||||
|
|
||||||
package com.ploedige.navdrawertest;
|
package com.ploedige.navdrawertest;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @author Paul Lödige (Matrikel: 15405036)
|
||||||
|
*/
|
||||||
|
|
||||||
package com.ploedige.navdrawertest.ui.slideshow;
|
package com.ploedige.navdrawertest.ui.slideshow;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -11,25 +15,23 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.ploedige.navdrawertest.R;
|
import com.ploedige.navdrawertest.R;
|
||||||
|
|
||||||
public class SlideshowFragment extends Fragment {
|
public class SlideshowFragment extends Fragment {
|
||||||
|
|
||||||
private SlideshowViewModel slideshowViewModel;
|
TestPagerAdapter testPagerAdapter;
|
||||||
|
ViewPager viewPager;
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
slideshowViewModel =
|
|
||||||
new ViewModelProvider(this).get(SlideshowViewModel.class);
|
|
||||||
View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
|
View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
|
||||||
final TextView textView = root.findViewById(R.id.text_slideshow);
|
|
||||||
slideshowViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
testPagerAdapter = new TestPagerAdapter(getFragmentManager());
|
||||||
@Override
|
|
||||||
public void onChanged(@Nullable String s) {
|
viewPager = (ViewPager) root.findViewById(R.id.pager);
|
||||||
textView.setText(s);
|
viewPager.setAdapter(testPagerAdapter);
|
||||||
}
|
|
||||||
});
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +0,0 @@
|
|||||||
package com.ploedige.navdrawertest.ui.slideshow;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
public class SlideshowViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private MutableLiveData<String> mText;
|
|
||||||
|
|
||||||
public SlideshowViewModel() {
|
|
||||||
mText = new MutableLiveData<>();
|
|
||||||
mText.setValue("This is slideshow fragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<String> getText() {
|
|
||||||
return mText;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* @author Paul Lödige (Matrikel: 15405036)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.ploedige.navdrawertest.ui.slideshow;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentPagerAdapter;
|
||||||
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
|
||||||
|
import com.ploedige.navdrawertest.ui.slideshow.fragments.SwipeFragment1;
|
||||||
|
import com.ploedige.navdrawertest.ui.slideshow.fragments.SwipeFragment2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TestPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
|
private Map<String, Class<? extends Fragment>> fragments = new HashMap();
|
||||||
|
|
||||||
|
public TestPagerAdapter(FragmentManager fm){
|
||||||
|
super(fm);
|
||||||
|
// add all the Classes for the SwipeView
|
||||||
|
fragments.put("Fragment 1", SwipeFragment1.class);
|
||||||
|
fragments.put("Fragment 2",SwipeFragment2.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
if(position >= fragments.size()){
|
||||||
|
Log.v("TestPagerAdapter","Position is outside of Array.");
|
||||||
|
return new SwipeFragment1();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return (Fragment) fragments.get(fragments.keySet().toArray()[position]).newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new SwipeFragment1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return fragments.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position){
|
||||||
|
return fragments.keySet().toArray()[position].toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* @author Paul Lödige (Matrikel: 15405036)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.ploedige.navdrawertest.ui.slideshow.fragments;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.ploedige.navdrawertest.R;
|
||||||
|
|
||||||
|
public class SwipeFragment1 extends Fragment {
|
||||||
|
|
||||||
|
public static SwipeFragment1 newInstance(String param1, String param2) {
|
||||||
|
SwipeFragment1 fragment = new SwipeFragment1();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_swipe1, container, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* @author Paul Lödige (Matrikel: 15405036)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.ploedige.navdrawertest.ui.slideshow.fragments;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.ploedige.navdrawertest.R;
|
||||||
|
|
||||||
|
public class SwipeFragment2 extends Fragment {
|
||||||
|
|
||||||
|
public static SwipeFragment2 newInstance(String param1, String param2) {
|
||||||
|
SwipeFragment2 fragment = new SwipeFragment2();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_swipe2, container, false);
|
||||||
|
}
|
||||||
|
}
|
@ -6,17 +6,15 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.slideshow.SlideshowFragment">
|
tools:context=".ui.slideshow.SlideshowFragment">
|
||||||
|
|
||||||
<TextView
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/text_slideshow"
|
android:id="@+id/pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent">
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginTop="8dp"
|
<androidx.viewpager.widget.PagerTabStrip
|
||||||
android:layout_marginEnd="8dp"
|
android:id="@+id/pts"
|
||||||
android:textAlignment="center"
|
android:layout_width="match_parent"
|
||||||
android:textSize="20sp"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:background="@color/design_default_color_secondary"/>
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
</androidx.viewpager.widget.ViewPager>
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
25
app/src/main/res/layout/fragment_swipe1.xml
Normal file
25
app/src/main/res/layout/fragment_swipe1.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout 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"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
tools:context=".ui.slideshow.fragments.SwipeFragment1">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="This is SwipeFragment1"
|
||||||
|
android:textSize="5mm"
|
||||||
|
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"/>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
25
app/src/main/res/layout/fragment_swipe2.xml
Normal file
25
app/src/main/res/layout/fragment_swipe2.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout 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"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
tools:context=".ui.slideshow.fragments.SwipeFragment2">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="This is SwipeFragment2"
|
||||||
|
android:textSize="5mm"
|
||||||
|
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"/>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</FrameLayout>
|
@ -10,4 +10,6 @@
|
|||||||
<string name="menu_home">Home</string>
|
<string name="menu_home">Home</string>
|
||||||
<string name="menu_gallery">Gallery</string>
|
<string name="menu_gallery">Gallery</string>
|
||||||
<string name="menu_slideshow">Slideshow</string>
|
<string name="menu_slideshow">Slideshow</string>
|
||||||
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user