Improves media
This commit is contained in:
parent
522b1d95e7
commit
bddb6d8672
|
@ -30,11 +30,11 @@ import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.MediaController;
|
import android.widget.MediaController;
|
||||||
|
@ -102,7 +102,6 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
private boolean canSwipe;
|
private boolean canSwipe;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private enum actionSwipe{
|
private enum actionSwipe{
|
||||||
RIGHT_TO_LEFT,
|
RIGHT_TO_LEFT,
|
||||||
LEFT_TO_RIGHT,
|
LEFT_TO_RIGHT,
|
||||||
|
@ -117,9 +116,9 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
if( theme == Helper.THEME_LIGHT){
|
if( theme == Helper.THEME_LIGHT){
|
||||||
setTheme(R.style.AppTheme);
|
setTheme(R.style.AppTheme_NoActionBar);
|
||||||
}else {
|
}else {
|
||||||
setTheme(R.style.AppThemeDark);
|
setTheme(R.style.AppThemeDark_NoActionBar);
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_media);
|
setContentView(R.layout.activity_media);
|
||||||
attachments = getIntent().getParcelableArrayListExtra("mediaArray");
|
attachments = getIntent().getParcelableArrayListExtra("mediaArray");
|
||||||
|
@ -128,7 +127,6 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
if( attachments == null || attachments.size() == 0)
|
if( attachments == null || attachments.size() == 0)
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
|
|
||||||
RelativeLayout main_container_media = findViewById(R.id.main_container_media);
|
RelativeLayout main_container_media = findViewById(R.id.main_container_media);
|
||||||
if( theme == Helper.THEME_LIGHT){
|
if( theme == Helper.THEME_LIGHT){
|
||||||
main_container_media.setBackgroundResource(R.color.mastodonC2);
|
main_container_media.setBackgroundResource(R.color.mastodonC2);
|
||||||
|
@ -136,8 +134,41 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
main_container_media.setBackgroundResource(R.color.mastodonC1);
|
main_container_media.setBackgroundResource(R.color.mastodonC1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
if( getSupportActionBar() != null) {
|
if( getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
assert inflater != null;
|
||||||
|
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.picture_actionbar, null);
|
||||||
|
getSupportActionBar().setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
|
||||||
|
|
||||||
|
ImageView action_save = getSupportActionBar().getCustomView().findViewById(R.id.action_save);
|
||||||
|
ImageView close = getSupportActionBar().getCustomView().findViewById(R.id.close);
|
||||||
|
if( close != null){
|
||||||
|
close.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
action_save.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if(Build.VERSION.SDK_INT >= 23 ){
|
||||||
|
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
|
||||||
|
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE);
|
||||||
|
} else {
|
||||||
|
Helper.manageMoveFileDownload(MediaActivity.this, preview_url, finalUrlDownload, downloadedImage, fileVideo);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Helper.manageMoveFileDownload(MediaActivity.this, preview_url, finalUrlDownload, downloadedImage, fileVideo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Handler h = new Handler();
|
Handler h = new Handler();
|
||||||
|
|
||||||
h.postDelayed(new Runnable() {
|
h.postDelayed(new Runnable() {
|
||||||
|
@ -204,34 +235,6 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
displayMediaAtPosition(actionSwipe.POP);
|
displayMediaAtPosition(actionSwipe.POP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
case R.id.action_download:
|
|
||||||
if(Build.VERSION.SDK_INT >= 23 ){
|
|
||||||
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
|
|
||||||
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE);
|
|
||||||
} else {
|
|
||||||
Helper.manageMoveFileDownload(MediaActivity.this, preview_url, finalUrlDownload, downloadedImage, fileVideo);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Helper.manageMoveFileDownload(MediaActivity.this, preview_url, finalUrlDownload, downloadedImage, fileVideo);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
|
||||||
getMenuInflater().inflate(R.menu.main_media, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage touch event
|
* Manage touch event
|
||||||
|
@ -252,7 +255,6 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
return super.dispatchTouchEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
|
if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
|
||||||
|
@ -429,15 +431,10 @@ public class MediaActivity extends AppCompatActivity {
|
||||||
filename = url;
|
filename = url;
|
||||||
if( attachments.size() > 1 )
|
if( attachments.size() > 1 )
|
||||||
filename = String.format("%s (%s/%s)",filename, mediaPosition, attachments.size());
|
filename = String.format("%s (%s/%s)",filename, mediaPosition, attachments.size());
|
||||||
|
|
||||||
LayoutInflater mInflater = LayoutInflater.from(MediaActivity.this);
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if( actionBar != null){
|
if( actionBar != null){
|
||||||
@SuppressLint("InflateParams") View picture_actionbar = mInflater.inflate(R.layout.picture_actionbar, null);
|
TextView picture_actionbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
||||||
TextView picture_actionbar_title = picture_actionbar.findViewById(R.id.picture_actionbar);
|
|
||||||
picture_actionbar_title.setText(filename);
|
picture_actionbar_title.setText(filename);
|
||||||
actionBar.setCustomView(picture_actionbar);
|
|
||||||
actionBar.setDisplayShowCustomEnabled(true);
|
|
||||||
}else {
|
}else {
|
||||||
setTitle(url);
|
setTitle(url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,22 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/main_container_media"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
>
|
android:id="@+id/main_container_media">
|
||||||
|
<android.support.design.widget.AppBarLayout
|
||||||
|
android:id="@+id/appBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:theme="@style/AppTheme.AppBarOverlay"
|
||||||
|
>
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:theme="@style/AppThemeDark_NoActionBar"
|
||||||
|
app:popupTheme="?attr/popupOverlay"/>
|
||||||
|
</android.support.design.widget.AppBarLayout>
|
||||||
<com.github.chrisbanes.photoview.PhotoView
|
<com.github.chrisbanes.photoview.PhotoView
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
|
|
|
@ -15,17 +15,53 @@
|
||||||
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
see <http://www.gnu.org/licenses>.
|
see <http://www.gnu.org/licenses>.
|
||||||
-->
|
-->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
|
<android.support.v7.widget.Toolbar 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:id="@+id/toolbar"
|
||||||
|
android:contentInsetLeft="0dp"
|
||||||
|
android:contentInsetStart="0dp"
|
||||||
|
app:contentInsetLeft="0dp"
|
||||||
|
app:contentInsetStart="0dp"
|
||||||
|
android:contentInsetRight="0dp"
|
||||||
|
android:contentInsetEnd="0dp"
|
||||||
|
app:contentInsetRight="0dp"
|
||||||
|
app:contentInsetEnd="0dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:background="?attr/colorPrimary"
|
||||||
>
|
app:popupTheme="?attr/popupOverlay"
|
||||||
|
tools:ignore="UnusedAttribute">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/close"
|
||||||
|
android:src="@drawable/ic_close"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:id="@+id/picture_actionbar"
|
android:id="@+id/toolbar_title"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="?attr/actionBarTextColor"
|
android:textColor="?attr/actionBarTextColor"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
<ImageView
|
||||||
|
android:id="@+id/action_save"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:src="@drawable/ic_save_white"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
</android.support.v7.widget.Toolbar>
|
Loading…
Reference in New Issue