-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7098c1b
Showing
56 changed files
with
1,310 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
id 'com.android.library' | ||
} | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
testImplementation 'junit:junit:4.+' | ||
implementation 'com.google.android.material:material:1.2.1' | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ir.khanbeiki.superviewpager"> | ||
|
||
</manifest> |
61 changes: 61 additions & 0 deletions
61
SuperViewpager/src/main/java/ir/khanbeiki/superviewpager/FragmentTime.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ir.khanbeiki.superviewpager; | ||
|
||
import java.io.Serializable; | ||
|
||
public class FragmentTime implements Serializable { | ||
private int id; | ||
private long runTime; | ||
private long minutes; | ||
private boolean isRun; | ||
private boolean isDisposable; | ||
|
||
public FragmentTime(int id, long minutes) { | ||
this.id = id; | ||
this.minutes = minutes; | ||
} | ||
|
||
public FragmentTime(int id, boolean isDisposable) { | ||
this.id = id; | ||
this.isDisposable = isDisposable; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public long getRunTime() { | ||
return runTime; | ||
} | ||
|
||
public void setRunTime(long runTime) { | ||
this.runTime = runTime; | ||
} | ||
|
||
public long getMinutes() { | ||
return minutes; | ||
} | ||
|
||
public void setMinutes(long minutes) { | ||
this.minutes = minutes; | ||
} | ||
|
||
public boolean isRun() { | ||
return isRun; | ||
} | ||
|
||
public void setRun(boolean run) { | ||
isRun = run; | ||
} | ||
|
||
public boolean isDisposable() { | ||
return isDisposable; | ||
} | ||
|
||
public void setDisposable(boolean disposable) { | ||
isDisposable = disposable; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
SuperViewpager/src/main/java/ir/khanbeiki/superviewpager/SuperViewPagerListener.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ir.khanbeiki.superviewpager; | ||
|
||
public interface SuperViewPagerListener { | ||
void onFragmentCommandDo(); | ||
void onFragmentAlwaysDo(); | ||
} |
153 changes: 153 additions & 0 deletions
153
SuperViewpager/src/main/java/ir/khanbeiki/superviewpager/TabAdapter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package ir.khanbeiki.superviewpager; | ||
|
||
import android.util.SparseArray; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
import androidx.fragment.app.FragmentPagerAdapter; | ||
import androidx.viewpager.widget.ViewPager; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
|
||
public class TabAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener { | ||
private final List<Fragment> mFragmentList = new ArrayList<>(); | ||
private final List<String> mFragmentTitleList = new ArrayList<>(); | ||
private final SparseArray<WeakReference<Fragment>> instantiatedFragments = new SparseArray<>(); | ||
private ArrayList<FragmentTime> ftList = new ArrayList<>(); | ||
private ViewPager mViewPager; | ||
|
||
public TabAdapter(@NonNull FragmentManager fm, int behavior) { | ||
super(fm, behavior); | ||
} | ||
|
||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return mFragmentList.get(position); | ||
} | ||
|
||
public void addFragment(Fragment fragment, String title) { | ||
mFragmentList.add(fragment); | ||
mFragmentTitleList.add(title); | ||
} | ||
|
||
// اگر isDisposable صحیح باشد فقط یکبار اجرا میشود | ||
public void addFragment(int id, boolean isDisposable, Fragment fragment, String title) { | ||
mFragmentList.add(fragment); | ||
mFragmentTitleList.add(title); | ||
ftList.add(new FragmentTime(id, isDisposable)); | ||
} | ||
|
||
// اگر minutes صفر نباشد در اون تایم به دقیقه اجرا میشود | ||
// اگر minutes صفر باشد هر بار اجرا میشود | ||
public void addFragment(int id, long minutes, Fragment fragment, String title) { | ||
mFragmentList.add(fragment); | ||
mFragmentTitleList.add(title); | ||
ftList.add(new FragmentTime(id, minutes)); | ||
} | ||
|
||
public void setViewPager(ViewPager viewPager) { | ||
this.mViewPager = viewPager; | ||
mViewPager.addOnPageChangeListener(this); | ||
} | ||
|
||
private long getMinutesMillisecond(long minutes) { | ||
return minutes * 60 * 1000; | ||
} | ||
|
||
private boolean getFragmentTimeOpened(int position) { | ||
for (FragmentTime fto : ftList) { | ||
if (fto.getId() == position) { | ||
if (fto.isDisposable()) { | ||
if (!fto.isRun()) { | ||
ftList.get(position).setRun(true); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
if (fto.getMinutes() == 0) { | ||
return true; | ||
} | ||
if (fto.getRunTime() == 0) { | ||
ftList.get(position).setRunTime(Calendar.getInstance().getTimeInMillis()); | ||
return true; | ||
} else { | ||
long time = Calendar.getInstance().getTimeInMillis() - fto.getRunTime(); | ||
if (time < getMinutesMillisecond(ftList.get(position).getMinutes())) { | ||
return false; | ||
} else { | ||
ftList.get(position).setRunTime(Calendar.getInstance().getTimeInMillis()); | ||
return true; | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public CharSequence getPageTitle(int position) { | ||
return mFragmentTitleList.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return mFragmentList.size(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Object instantiateItem(@NonNull ViewGroup container, int position) { | ||
final Fragment fragment = (Fragment) super.instantiateItem(container, position); | ||
instantiatedFragments.put(position, new WeakReference<>(fragment)); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { | ||
instantiatedFragments.remove(position); | ||
super.destroyItem(container, position, object); | ||
} | ||
|
||
@Nullable | ||
Fragment getFragment(final int position) { | ||
final WeakReference<Fragment> wr = instantiatedFragments.get(position); | ||
if (wr != null) { | ||
return wr.get(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
if (positionOffset == 0) { | ||
SuperViewPagerListener fragment = (SuperViewPagerListener) instantiateItem(mViewPager, position); | ||
if (getFragmentTimeOpened(position)) { | ||
fragment.onFragmentCommandDo(); | ||
} | ||
fragment.onFragmentAlwaysDo(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPageSelected(int i) { | ||
|
||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int i) { | ||
|
||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Oops, something went wrong.