mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Separate ShareView into an activity + a fragment
This commit is contained in:
parent
f0e9d30bfa
commit
1816f792f8
4 changed files with 156 additions and 84 deletions
|
|
@ -12,34 +12,10 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="fill"
|
||||
android:background="#AA000000"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dip"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingTop="8dip" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/titleEdit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollHorizontally="false"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/share_title_hint"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/descEdit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/share_description_hint"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/single_upload_fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
30
commons/res/layout/fragment_single_upload.xml
Normal file
30
commons/res/layout/fragment_single_upload.xml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="fill"
|
||||
android:background="#AA000000"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dip"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingTop="8dip" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/titleEdit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollHorizontally="false"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/share_title_hint"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/descEdit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/share_description_hint"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
|
@ -17,7 +17,9 @@ import org.wikimedia.commons.auth.*;
|
|||
import org.wikimedia.commons.modifications.PostUploadActivity;
|
||||
|
||||
|
||||
public class ShareActivity extends AuthenticatedActivity {
|
||||
public class ShareActivity extends AuthenticatedActivity implements SingleUploadFragment.OnUploadActionInitiated {
|
||||
|
||||
private SingleUploadFragment shareView;
|
||||
|
||||
public ShareActivity() {
|
||||
super(WikiAccountAuthenticator.COMMONS_ACCOUNT_TYPE);
|
||||
|
|
@ -25,15 +27,13 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
|
||||
private CommonsApplication app;
|
||||
|
||||
private ImageView backgroundImageView;
|
||||
private EditText titleEdit;
|
||||
private EditText descEdit;
|
||||
|
||||
private String source;
|
||||
private String mimeType;
|
||||
|
||||
private Uri mediaUri;
|
||||
|
||||
private ImageView backgroundImageView;
|
||||
|
||||
private UploadService uploadService;
|
||||
private boolean isUploadServiceConnected;
|
||||
private ServiceConnection uploadServiceConnection = new ServiceConnection() {
|
||||
|
|
@ -48,6 +48,11 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
}
|
||||
};
|
||||
|
||||
public void uploadActionInitiated(String title, String description) {
|
||||
StartUploadTask task = new SingleStartUploadTask(ShareActivity.this, uploadService, title, mediaUri, description, mimeType, source);
|
||||
task.execute();
|
||||
|
||||
}
|
||||
|
||||
private class SingleStartUploadTask extends StartUploadTask {
|
||||
|
||||
|
|
@ -85,6 +90,41 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
protected void onAuthCookieAcquired(String authCookie) {
|
||||
super.onAuthCookieAcquired(authCookie);
|
||||
app.getApi().setAuthCookie(authCookie);
|
||||
|
||||
|
||||
shareView = (SingleUploadFragment) getSupportFragmentManager().findFragmentByTag("shareView");
|
||||
if(shareView == null) {
|
||||
shareView = new SingleUploadFragment();
|
||||
this.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(R.id.single_upload_fragment_container, shareView, "shareView")
|
||||
.commit();
|
||||
}
|
||||
|
||||
Intent uploadServiceIntent = new Intent(getApplicationContext(), UploadService.class);
|
||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||
startService(uploadServiceIntent);
|
||||
bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAuthFailure() {
|
||||
super.onAuthFailure();
|
||||
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
|
||||
failureToast.show();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_share);
|
||||
|
||||
app = (CommonsApplication)this.getApplicationContext();
|
||||
|
||||
backgroundImageView = (ImageView)findViewById(R.id.backgroundImage);
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
if(intent.getAction().equals(Intent.ACTION_SEND)) {
|
||||
|
|
@ -96,60 +136,11 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
}
|
||||
|
||||
mimeType = intent.getType();
|
||||
if(mimeType.startsWith("image/")) {
|
||||
ImageLoader.getInstance().displayImage(mediaUri.toString(), backgroundImageView);
|
||||
}
|
||||
|
||||
Intent uploadServiceIntent = new Intent(getApplicationContext(), UploadService.class);
|
||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||
startService(uploadServiceIntent);
|
||||
bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onAuthFailure() {
|
||||
super.onAuthFailure();
|
||||
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
|
||||
failureToast.show();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_share);
|
||||
|
||||
app = (CommonsApplication)this.getApplicationContext();
|
||||
|
||||
backgroundImageView = (ImageView)findViewById(R.id.backgroundImage);
|
||||
titleEdit = (EditText)findViewById(R.id.titleEdit);
|
||||
descEdit = (EditText)findViewById(R.id.descEdit);
|
||||
|
||||
TextWatcher uploadEnabler = new TextWatcher() {
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
|
||||
|
||||
public void afterTextChanged(Editable editable) {
|
||||
actionMenu.findItem(R.id.menu_upload_single).setEnabled(titleEdit.getText().length() != 0);
|
||||
}
|
||||
};
|
||||
|
||||
titleEdit.addTextChangedListener(uploadEnabler);
|
||||
ImageLoader.getInstance().displayImage(mediaUri.toString(), backgroundImageView);
|
||||
|
||||
requestAuthToken();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -160,25 +151,12 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private Menu actionMenu;
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getSupportMenuInflater().inflate(R.menu.activity_share, menu);
|
||||
actionMenu = menu;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
NavUtils.navigateUpFromSameTask(this);
|
||||
return true;
|
||||
case R.id.menu_upload_single:
|
||||
StartUploadTask task = new SingleStartUploadTask(ShareActivity.this, uploadService, titleEdit.getText().toString(), mediaUri, descEdit.getText().toString(), mimeType, source);
|
||||
task.execute();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
|
||||
public class SingleUploadFragment extends SherlockFragment {
|
||||
|
||||
public interface OnUploadActionInitiated {
|
||||
void uploadActionInitiated(String title, String description);
|
||||
}
|
||||
|
||||
private EditText titleEdit;
|
||||
private EditText descEdit;
|
||||
|
||||
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
||||
|
||||
private Menu actionMenu;
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.activity_share, menu);
|
||||
actionMenu = menu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_upload_single:
|
||||
uploadActionInitiatedHandler.uploadActionInitiated(titleEdit.getText().toString(), descEdit.getText().toString());
|
||||
return true;
|
||||
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_single_upload, null);
|
||||
|
||||
titleEdit = (EditText)rootView.findViewById(R.id.titleEdit);
|
||||
descEdit = (EditText)rootView.findViewById(R.id.descEdit);
|
||||
|
||||
TextWatcher uploadEnabler = new TextWatcher() {
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
|
||||
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
|
||||
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(actionMenu == null) {
|
||||
getSherlockActivity().invalidateOptionsMenu();
|
||||
}
|
||||
actionMenu.findItem(R.id.menu_upload_single).setEnabled(titleEdit.getText().length() != 0);
|
||||
}
|
||||
};
|
||||
|
||||
titleEdit.addTextChangedListener(uploadEnabler);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
uploadActionInitiatedHandler = (OnUploadActionInitiated) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue