-
Notifications
You must be signed in to change notification settings - Fork 0
Улучшение вступительного испытания #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4054e19
59f6219
0e6439c
4dec61b
7181368
1e553c1
f8c4dc4
5270e61
57d6cfe
7fe1406
cf90a82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.example.android.yamsd; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.view.LayoutInflater; | ||
| import android.view.Menu; | ||
| import android.view.MenuInflater; | ||
| import android.view.MenuItem; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
|
|
||
| public class AboutFragment extends Fragment { | ||
|
|
||
| public AboutFragment() { | ||
| } | ||
|
|
||
| public static AboutFragment newInstance() { | ||
| return new AboutFragment(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setHasOptionsMenu(true); | ||
| } | ||
|
|
||
| @Override | ||
| public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | ||
| super.onCreateOptionsMenu(menu, inflater); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| switch (item.getItemId()) { | ||
| case R.id.action_refresh: | ||
| CacheAndListBuffer | ||
| .getCacheAndListBuffer( | ||
| getActivity() | ||
| ) | ||
| .updateArtists(true); | ||
| return true; | ||
| case R.id.action_about: | ||
| AboutFragment aboutFragment = | ||
| AboutFragment.newInstance(); | ||
|
|
||
| android.support.v4.app.FragmentTransaction fragmentTransaction = | ||
| getFragmentManager().beginTransaction(); | ||
|
|
||
| fragmentTransaction.replace( | ||
| R.id.fragment_container, | ||
| aboutFragment | ||
| ); | ||
| fragmentTransaction.addToBackStack(null); | ||
| fragmentTransaction.commit(); | ||
|
|
||
| return true; | ||
| case R.id.action_feedback: | ||
| EmailSender.sendMessage(getContext()); | ||
| return true; | ||
| default: | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
| Bundle savedInstanceState) { | ||
| // Inflate the layout for this fragment | ||
| View rootView = inflater.inflate(R.layout.fragment_about, container, false); | ||
| View sendEmailButton = | ||
| rootView.findViewById(R.id.SEND_EMAIL_BUTTON); | ||
|
|
||
| sendEmailButton.setOnClickListener( | ||
| new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| EmailSender.sendMessage(getContext()); | ||
| } | ||
| } | ||
| ); | ||
| return rootView; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void onResume() { | ||
| super.onResume(); | ||
| checkNotNull(((AppCompatActivity) getActivity()) | ||
| .getSupportActionBar()) | ||
| .setTitle("О приложении"); | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,20 @@ | ||
| package com.example.android.yamsd; | ||
|
|
||
| import android.content.Intent; | ||
| import android.graphics.Bitmap; | ||
| import android.os.AsyncTask; | ||
| import android.os.Bundle; | ||
| import android.support.v4.app.Fragment; | ||
| import android.util.Log; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.view.LayoutInflater; | ||
| import android.view.Menu; | ||
| import android.view.MenuInflater; | ||
| import android.view.MenuItem; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.example.android.yamsd.ArtistsData.Artist; | ||
| import com.squareup.picasso.Picasso; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| /** | ||
| * Фрагмент с информацией об одном артисте. | ||
| */ | ||
|
|
@@ -22,41 +23,96 @@ public class ArtistActivityFragment extends Fragment { | |
|
|
||
| private String LOG_TAG = getClass().getSimpleName(); | ||
|
|
||
| Artist artist; | ||
|
|
||
|
|
||
| public static ArtistActivityFragment newInstance(int index) { | ||
| ArtistActivityFragment artistActivityFragment = | ||
| new ArtistActivityFragment(); | ||
|
|
||
| Bundle args = new Bundle(); | ||
| args.putInt("index", index); | ||
| artistActivityFragment.setArguments(args); | ||
|
|
||
| return artistActivityFragment; | ||
| } | ||
|
|
||
|
|
||
| public ArtistActivityFragment() { | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
| Bundle savedInstanceState) { | ||
| public void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setHasOptionsMenu(true); | ||
| } | ||
|
|
||
| try { | ||
|
|
||
| Intent artistInfoIntent = getActivity().getIntent(); | ||
| Artist artist = | ||
| new Artist( | ||
| artistInfoIntent.getStringExtra("name"), | ||
| @Override | ||
| public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не нужный отладочный код.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Странно, я думал, что я его удалил. |
||
| super.onCreateOptionsMenu(menu, inflater); | ||
| } | ||
|
|
||
| artistInfoIntent.getStringArrayExtra("genres"), | ||
|
|
||
| artistInfoIntent.getIntExtra("albums", 0), | ||
| artistInfoIntent.getIntExtra("tracks", 0), | ||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| switch (item.getItemId()) { | ||
| case R.id.action_refresh: | ||
| CacheAndListBuffer | ||
| .getCacheAndListBuffer( | ||
| getActivity() | ||
| ) | ||
| .updateArtists(true); | ||
| return true; | ||
| case R.id.action_about: | ||
| AboutFragment aboutFragment = | ||
| AboutFragment.newInstance(); | ||
|
|
||
| getFragmentManager() | ||
| .beginTransaction() | ||
| .replace( | ||
| R.id.fragment_container, | ||
| aboutFragment | ||
| ) | ||
| .addToBackStack(null) | ||
| .commit(); | ||
|
|
||
| return true; | ||
|
|
||
| case R.id.action_feedback: | ||
| EmailSender.sendMessage(getContext()); | ||
| return true; | ||
|
|
||
| default: | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
| } | ||
|
|
||
| artistInfoIntent.getStringExtra("description"), | ||
|
|
||
| artistInfoIntent.getStringExtra("bigCover") | ||
| ); | ||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
| Bundle savedInstanceState) { | ||
|
|
||
| return loadArtistData(artist, inflater).getRootView(); | ||
| } catch (NullPointerException e) { | ||
| Log.e( | ||
| LOG_TAG, | ||
| "Null Pointer Exception while creating view: " + e | ||
| ); | ||
| } | ||
| int artistInfoIndex = getArguments().getInt("index", 0); | ||
| artist = | ||
| CacheAndListBuffer | ||
| .getCacheAndListBuffer( | ||
| getActivity() | ||
| ) | ||
| .getArtists() | ||
| .get(artistInfoIndex); | ||
|
|
||
| return null; | ||
| return loadArtistData(artist, inflater).getRootView(); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void onResume() { | ||
| super.onResume(); | ||
| checkNotNull(((AppCompatActivity) getActivity()) | ||
| .getSupportActionBar()) | ||
| .setTitle(artist.getName()); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -70,48 +126,14 @@ private ArtistViewHolder loadArtistData( | |
| "Artist", | ||
| artist | ||
| ); | ||
| new loadBigCoverTask(viewHolder).execute(artist); | ||
|
|
||
| Picasso | ||
| .with(getContext()) | ||
| .load(artist.getBigCoverUrlString()) | ||
| .into(viewHolder.cover); | ||
|
|
||
| return viewHolder; | ||
| } | ||
|
|
||
|
|
||
| private class loadBigCoverTask | ||
| extends AsyncTask<Artist, Void, Bitmap> { | ||
| private String LOG_TAG = getClass().getSimpleName(); | ||
|
|
||
| Artist artist; | ||
| ArtistViewHolder viewHolder; | ||
|
|
||
|
|
||
| public loadBigCoverTask(ArtistViewHolder viewHolder) { | ||
| this.viewHolder = viewHolder; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected Bitmap doInBackground(Artist... params) { | ||
| try { | ||
| artist = params[0]; | ||
|
|
||
| return (Bitmap) Utility.downloadData( | ||
| new URL(params[0].getBigCoverUrlString()), | ||
| "bitmap" | ||
| ); | ||
|
|
||
| } catch (IOException e) { | ||
| Log.e(LOG_TAG, "Error while loading image: " + e); | ||
| } catch (NullPointerException e){ | ||
| Log.e(LOG_TAG, "Null pointer while loading image: " + e); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected void onPostExecute(Bitmap bitmap) { | ||
| viewHolder.setCoverBitmap(bitmap); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чо за дырки в коде?
Один перенос для разделения методов - OK. Два - перебор.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Думал таким образом разделять методы. Там внутри разделяю, так сказать, логические блоки одним переносом.