Skip to content

Commit

Permalink
feat: application introduction slides added
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-299 committed May 17, 2020
1 parent 6fbe4f8 commit 9252db4
Show file tree
Hide file tree
Showing 28 changed files with 449 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ dependencies {

//multidex
implementation "androidx.multidex:multidex:$rootProject.multiDexVersion"

//TableView
implementation "com.evrencoskun.library:tableview:$rootProject.tableViewVersion"

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
</intent-filter>
</activity>

<activity android:name=".ui.activities.IntroductionActivity"/>

<activity
android:configChanges="screenLayout|screenSize"
android:label="@string/home"
Expand Down Expand Up @@ -150,4 +152,4 @@
<activity android:name="org.mifos.mobile.ui.activities.SettingsActivity"/>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package org.mifos.mobile.ui.activities;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.mifos.mobile.R;
import org.mifos.mobile.api.local.PreferencesHelper;
import org.mifos.mobile.ui.adapters.IntroductionViewPagerAdapter;
import org.mifos.mobile.utils.CheckSelfPermissionAndRequest;
import org.mifos.mobile.utils.Constants;

public class IntroductionActivity extends AppCompatActivity {

@BindView(R.id.view_pager)
public ViewPager viewPager;

@BindView(R.id.layoutDots)
public LinearLayout dotsLayout;

@BindView(R.id.btn_skip)
public Button btnSkip;

@BindView(R.id.btn_next)
public Button btnNext;

private IntroductionViewPagerAdapter myViewPagerAdapter;
private TextView[] dots;
private int[] layouts;
private PreferencesHelper prefs;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_introduction);
ButterKnife.bind(this);

prefs = new PreferencesHelper(this);
layouts = new int[]{
R.layout.intro_screen_1,
R.layout.intro_screen_2,
R.layout.intro_screen_3,
R.layout.intro_screen_4};

addBottomDots(0);
myViewPagerAdapter = new IntroductionViewPagerAdapter(layouts, this);
viewPager.setAdapter(myViewPagerAdapter);
viewPager.addOnPageChangeListener(viewPagerPageChangeListener);

btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchHomeScreen();
}
});
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int current = getItem(+1);
if (current < layouts.length) {
if (current == 2 && !CheckSelfPermissionAndRequest
.checkSelfPermission(getApplicationContext(),
Manifest.permission.READ_PHONE_STATE)) {
requestPermission();
}
viewPager.setCurrentItem(current);
} else {
launchHomeScreen();
}
}
});
}


private void addBottomDots(int currentPage) {
int colorInactive = getResources().getColor(R.color.primary);
int colorActive = getResources().getColor(R.color.white);
dots = new TextView[layouts.length];

dotsLayout.removeAllViews();
for (int i = 0; i < dots.length; i++) {
dots[i] = new TextView(this);
dots[i].setText(Html.fromHtml(getString(R.string.dot_string)));
dots[i].setTextSize(35);
dots[i].setTextColor(colorInactive);
dotsLayout.addView(dots[i]);
}
if (dots.length > 0) {
dots[currentPage].setTextColor(colorActive);
}
}

private int getItem(int i) {
return viewPager.getCurrentItem() + i;
}

private void launchHomeScreen() {
prefs.putBoolean("check_first_time", false);
startActivity(new Intent(this, LoginActivity.class));
finish();
}


ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager
.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
addBottomDots(position);

if (position == layouts.length - 1) {
btnNext.setText(getString(R.string.start));
btnSkip.setVisibility(View.GONE);
} else if (position == 2 && !CheckSelfPermissionAndRequest
.checkSelfPermission(getApplicationContext(),
Manifest.permission.READ_PHONE_STATE)) {
requestPermission();
} else {
btnNext.setText(getString(R.string.next));
btnSkip.setVisibility(View.VISIBLE);
}
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) { }

@Override
public void onPageScrollStateChanged(int arg0) { }
};


/**
* Uses {@link CheckSelfPermissionAndRequest} to check for runtime permissions
*/
private void requestPermission() {
CheckSelfPermissionAndRequest.requestPermission(
this,
Manifest.permission.READ_PHONE_STATE,
Constants.PERMISSIONS_REQUEST_READ_PHONE_STATE,
getResources().getString(
R.string.dialog_message_phone_state_permission_denied_prompt),
getResources().getString(R.string.
dialog_message_phone_state_permission_never_ask_again),
Constants.PERMISSIONS_READ_PHONE_STATE_STATUS);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mifos.mobile.ui.activities;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -10,8 +9,6 @@
import com.mifos.mobile.passcode.utils.EncryptionUtil;

import org.mifos.mobile.R;
import org.mifos.mobile.utils.CheckSelfPermissionAndRequest;
import org.mifos.mobile.utils.Constants;
import org.mifos.mobile.utils.MaterialDialog;
import org.mifos.mobile.utils.Toaster;

Expand All @@ -20,26 +17,8 @@ public class PassCodeActivity extends MifosPassCodeActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!CheckSelfPermissionAndRequest.checkSelfPermission(this,
Manifest.permission.READ_PHONE_STATE)) {
requestPermission();
}
}

/**
* Uses {@link CheckSelfPermissionAndRequest} to check for runtime permissions
*/
private void requestPermission() {
CheckSelfPermissionAndRequest.requestPermission(
this,
Manifest.permission.READ_PHONE_STATE,
Constants.PERMISSIONS_REQUEST_READ_PHONE_STATE,
getResources().getString(
R.string.dialog_message_phone_state_permission_denied_prompt),
getResources().getString(R.string.
dialog_message_phone_state_permission_never_ask_again),
Constants.PERMISSIONS_READ_PHONE_STATE_STATUS);
}

@Override
public int getLogo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper;

import org.mifos.mobile.api.local.PreferencesHelper;
import org.mifos.mobile.ui.activities.base.BaseActivity;
import org.mifos.mobile.utils.Constants;

public class SplashActivity extends BaseActivity {

PasscodePreferencesHelper passcodePreferencesHelper;
PreferencesHelper prefs;
Intent intent;

@Override
Expand All @@ -23,9 +25,13 @@ protected void onCreate(Bundle savedInstanceState) {
getActivityComponent().inject(this);

passcodePreferencesHelper = new PasscodePreferencesHelper(this);
prefs = new PreferencesHelper(this);
if (!passcodePreferencesHelper.getPassCode().isEmpty()) {
intent = new Intent(this, PassCodeActivity.class);
intent.putExtra(Constants.INTIAL_LOGIN, true);
} else if (passcodePreferencesHelper.getPassCode().isEmpty() &&
prefs.getBoolean("check_first_time", true)) {
intent = new Intent(this, IntroductionActivity.class);
} else {
intent = new Intent(this, LoginActivity.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.mifos.mobile.ui.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

public class IntroductionViewPagerAdapter extends PagerAdapter {

private LayoutInflater layoutInflater;
private int[] layouts;
Context context;

public IntroductionViewPagerAdapter(int[] layoutArray, Context context) {
layouts = layoutArray;
this.context = context;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(layouts[position], container, false);
container.addView(view);
return view;
}

@Override
public int getCount() {
return layouts.length;
}

@Override
public boolean isViewFromObject(View view, Object obj) {
return view == obj;
}


@Override
public void destroyItem(ViewGroup container, int position, Object object) {
View view = (View) object;
container.removeView(view);
}
}
Binary file added app/src/main/res/drawable-hdpi/ic_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/ic_done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/ic_intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions app/src/main/res/layout/activity_introduction.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:showIn="@layout/activity_introduction">


<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<LinearLayout
android:id="@+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="@dimen/dots_height"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:gravity="center"
android:orientation="horizontal"></LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha=".5"
android:layout_above="@id/layoutDots"
android:background="@android:color/white" />

<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@null"
android:text="@string/next"
android:textColor="@android:color/white" />

<Button
android:id="@+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@null"
android:text="@string/skip"
android:textColor="@android:color/white" />

</RelativeLayout>
39 changes: 39 additions & 0 deletions app/src/main/res/layout/intro_screen_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_dark">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:orientation="vertical">

<ImageView
android:layout_width="@dimen/img_width_height"
android:layout_height="@dimen/img_width_height"
android:src="@mipmap/mifos_icon" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/slide_1_title"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_title"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:text="@string/slide_1_desc"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_desc" />

</LinearLayout>
</RelativeLayout>
Loading

0 comments on commit 9252db4

Please sign in to comment.