-
Notifications
You must be signed in to change notification settings - Fork 275
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
1 parent
ea5bd17
commit 4476343
Showing
8 changed files
with
266 additions
and
47 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
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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/org/amahi/anywhere/adapter/ServerFileImagePagerAdapter.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,53 @@ | ||
/* | ||
* Copyright (c) 2014 Amahi | ||
* | ||
* This file is part of Amahi. | ||
* | ||
* Amahi is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Amahi is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Amahi. If not, see <http ://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.amahi.anywhere.adapter; | ||
|
||
import android.app.Fragment; | ||
import android.app.FragmentManager; | ||
import android.support.v13.app.FragmentStatePagerAdapter; | ||
|
||
import org.amahi.anywhere.server.model.ServerFile; | ||
import org.amahi.anywhere.server.model.ServerShare; | ||
import org.amahi.anywhere.util.Fragments; | ||
|
||
import java.util.List; | ||
|
||
public class ServerFileImagePagerAdapter extends FragmentStatePagerAdapter | ||
{ | ||
private final ServerShare imageShare; | ||
private final List<ServerFile> imageFiles; | ||
|
||
public ServerFileImagePagerAdapter(FragmentManager fragmentManager, ServerShare imageShare, List<ServerFile> imageFiles) { | ||
super(fragmentManager); | ||
|
||
this.imageShare = imageShare; | ||
this.imageFiles = imageFiles; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return imageFiles.size(); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int imagePosition) { | ||
return Fragments.Builder.buildServerFileImageFragment(imageShare, imageFiles.get(imagePosition)); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/org/amahi/anywhere/fragment/ServerFileImageFragment.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,108 @@ | ||
/* | ||
* Copyright (c) 2014 Amahi | ||
* | ||
* This file is part of Amahi. | ||
* | ||
* Amahi is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Amahi is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Amahi. If not, see <http ://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.amahi.anywhere.fragment; | ||
|
||
import android.app.Fragment; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.ViewAnimator; | ||
|
||
import com.squareup.picasso.Callback; | ||
import com.squareup.picasso.Picasso; | ||
|
||
import org.amahi.anywhere.AmahiApplication; | ||
import org.amahi.anywhere.R; | ||
import org.amahi.anywhere.server.client.ServerClient; | ||
import org.amahi.anywhere.server.model.ServerFile; | ||
import org.amahi.anywhere.server.model.ServerShare; | ||
import org.amahi.anywhere.util.Fragments; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class ServerFileImageFragment extends Fragment implements Callback | ||
{ | ||
@Inject | ||
ServerClient serverClient; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) { | ||
return layoutInflater.inflate(R.layout.fragment_server_file_image, container, false); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
|
||
setUpInjections(); | ||
|
||
setUpImage(); | ||
} | ||
|
||
private void setUpInjections() { | ||
AmahiApplication.from(getActivity()).inject(this); | ||
} | ||
|
||
private void setUpImage() { | ||
setUpImageContent(); | ||
} | ||
|
||
private void setUpImageContent() { | ||
Picasso | ||
.with(getActivity()) | ||
.load(getImageUri()) | ||
.fit() | ||
.centerInside() | ||
.into(getImageView(), this); | ||
} | ||
|
||
private Uri getImageUri() { | ||
return serverClient.getFileUri(getShare(), getFile()); | ||
} | ||
|
||
private ServerShare getShare() { | ||
return getArguments().getParcelable(Fragments.Arguments.SERVER_SHARE); | ||
} | ||
|
||
private ServerFile getFile() { | ||
return getArguments().getParcelable(Fragments.Arguments.SERVER_FILE); | ||
} | ||
|
||
private ImageView getImageView() { | ||
return (ImageView) getView().findViewById(R.id.image); | ||
} | ||
|
||
@Override | ||
public void onSuccess() { | ||
showImageContent(); | ||
} | ||
|
||
private void showImageContent() { | ||
ViewAnimator animator = (ViewAnimator) getView().findViewById(R.id.animator); | ||
animator.setDisplayedChild(animator.indexOfChild(getView().findViewById(R.id.image))); | ||
} | ||
|
||
@Override | ||
public void onError() { | ||
} | ||
} |
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
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
Oops, something went wrong.