Moved EditPagerAdapater to own file and allowed both pages to be displayed on landscape layout (also improved edit fragment padding)
This commit is contained in:
parent
b1fb0dcea0
commit
66f61ddc65
4 changed files with 79 additions and 45 deletions
|
@ -24,6 +24,9 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
dexOptions {
|
||||
jumboMode true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.wbrawner.simplemarkdown;
|
||||
|
||||
/**
|
||||
* Created by billy on 7/29/2017.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import static com.wbrawner.simplemarkdown.MainActivity.FRAGMENT_EDIT;
|
||||
import static com.wbrawner.simplemarkdown.MainActivity.FRAGMENT_PREVIEW;
|
||||
import static com.wbrawner.simplemarkdown.MainActivity.NUM_PAGES;
|
||||
|
||||
class EditPagerAdapter extends FragmentPagerAdapter {
|
||||
private Context mContext;
|
||||
|
||||
public EditPagerAdapter(FragmentManager fm, Context context) {
|
||||
super(fm);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case FRAGMENT_EDIT:
|
||||
return new EditFragment();
|
||||
case FRAGMENT_PREVIEW:
|
||||
return new PreviewFragment();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NUM_PAGES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
int stringId = 0;
|
||||
switch (position) {
|
||||
case FRAGMENT_EDIT:
|
||||
stringId = R.string.action_edit;
|
||||
break;
|
||||
case FRAGMENT_PREVIEW:
|
||||
stringId = R.string.action_preview;
|
||||
break;
|
||||
}
|
||||
return mContext.getString(stringId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPageWidth(int position) {
|
||||
if (mContext.getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_LANDSCAPE) {
|
||||
return 0.5f;
|
||||
}
|
||||
return super.getPageWidth(position);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,11 @@ import android.Manifest;
|
|||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -29,6 +31,7 @@ import android.util.Log;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SearchEvent;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
@ -44,6 +47,10 @@ public class MainActivity extends AppCompatActivity
|
|||
public static final String AUTHORITY = "com.wbrawner.simplemarkdown.fileprovider";
|
||||
private static final int REQUEST_WRITE_STORAGE = 0;
|
||||
private static File mFilesDir;
|
||||
public static final int FRAGMENT_EDIT = 0;
|
||||
public static final int FRAGMENT_PREVIEW = 1;
|
||||
public static final int NUM_PAGES = 2;
|
||||
|
||||
@BindView(R.id.pager)
|
||||
ViewPager pager;
|
||||
@BindView(R.id.layout_tab)
|
||||
|
@ -83,7 +90,9 @@ public class MainActivity extends AppCompatActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
pager.setAdapter(new EditPagerAdapter(getSupportFragmentManager()));
|
||||
pager.setAdapter(
|
||||
new EditPagerAdapter(getSupportFragmentManager(), MainActivity.this)
|
||||
);
|
||||
mFilesDir = getFilesDir();
|
||||
checkDirectories();
|
||||
Intent intent = getIntent();
|
||||
|
@ -231,53 +240,12 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EditPagerAdapter extends FragmentPagerAdapter {
|
||||
private static final int FRAGMENT_EDIT = 0;
|
||||
public static final int FRAGMENT_PREVIEW = 1;
|
||||
private static final int NUM_PAGES = 2;
|
||||
|
||||
public EditPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case FRAGMENT_EDIT:
|
||||
return new EditFragment();
|
||||
case FRAGMENT_PREVIEW:
|
||||
return new PreviewFragment();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NUM_PAGES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
int stringId = 0;
|
||||
switch (position) {
|
||||
case FRAGMENT_EDIT:
|
||||
stringId = R.string.action_edit;
|
||||
break;
|
||||
case FRAGMENT_PREVIEW:
|
||||
stringId = R.string.action_preview;
|
||||
break;
|
||||
}
|
||||
return getString(stringId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (pager.getCurrentItem() == EditPagerAdapter.FRAGMENT_EDIT)
|
||||
if (pager.getCurrentItem() == FRAGMENT_EDIT)
|
||||
super.onBackPressed();
|
||||
else
|
||||
pager.setCurrentItem(EditPagerAdapter.FRAGMENT_EDIT);
|
||||
pager.setCurrentItem(FRAGMENT_EDIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp"
|
||||
tools:context="com.wbrawner.simplemarkdown.EditFragment">
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
|
@ -10,6 +9,7 @@
|
|||
android:id="@+id/markdown_edit"
|
||||
android:inputType="textMultiLine"
|
||||
android:background="@null"
|
||||
android:padding="8dp"
|
||||
android:hint="@string/markdown_here"
|
||||
android:scrollHorizontally="false" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue