Skip to content

Commit

Permalink
realm 업그레이드
Browse files Browse the repository at this point in the history
재생목록 리스트 표시
realm 저장방식 변경
  • Loading branch information
LNTCS committed Jul 8, 2016
1 parent 3e3ad36 commit 0bd10a0
Show file tree
Hide file tree
Showing 16 changed files with 424 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
Expand Down Expand Up @@ -57,7 +58,6 @@ dependencies {
transitive = true
}
compile 'io.karim:materialtabs:2.0.3'
compile 'io.realm:realm-android:0.87.5'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'ua.com.crosp.solutions.library:pretty-toast:0.1.1'
compile 'com.github.orhanobut:logger:1.12'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<data android:scheme="vnd.youtube" />
</intent-filter>
</activity>
<activity android:name=".PlayListActivity"/>
<service android:name=".PlayService"/>
</application>
</manifest>
6 changes: 5 additions & 1 deletion app/src/main/java/kr/edcan/u_stream/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import butterknife.OnClick;
import es.dmoral.prefs.Prefs;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import kr.edcan.u_stream.adapter.MainAdapter;
import kr.edcan.u_stream.model.MusicData;
import kr.edcan.u_stream.model.RM_MusicData;
Expand All @@ -45,6 +46,8 @@ public class MainActivity extends AppCompatActivity{
public static TextView playingSubtitle;
public static ImageButton playBtn;

private Realm realm;
private RealmConfiguration realmConfig;
MainAdapter adapter;

@Override
Expand Down Expand Up @@ -78,7 +81,8 @@ public void onPageSelected(int position) {
public void onPageScrollStateChanged(int state) {
}
});
Realm realm = Realm.getInstance(this);
realmConfig = new RealmConfiguration.Builder(this).build();
realm = Realm.getInstance(realmConfig);
if(PlayService.mediaPlayer == null) {
MusicData latest = new Gson().fromJson(Prefs.with(this).read("latestPlay"), MusicData.class);
if (latest != null) {
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/kr/edcan/u_stream/PlayListActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package kr.edcan.u_stream;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.TextView;

import com.orhanobut.logger.Logger;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import kr.edcan.u_stream.adapter.PlaylistListAdapter;
import kr.edcan.u_stream.model.MusicData;
import kr.edcan.u_stream.model.RM_MusicData;

/**
* Created by LNTCS on 2016-07-08.
*/
public class PlayListActivity extends AppCompatActivity {

@Bind(R.id.toolbar_title)
TextView toolbarTitle;
@Bind(R.id.playlist_list)
ListView listView;

ArrayList<MusicData> mList = new ArrayList<>();

private Realm realm;
private RealmConfiguration realmConfig;
PlaylistListAdapter playlistListAdapter;

Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playlist);
ButterKnife.bind(this);
Logger.init("asdf");
mContext = this;
toolbarTitle.setText(getIntent().getStringExtra("title"));
realmConfig = new RealmConfiguration.Builder(mContext).build();
realm = Realm.getInstance(realmConfig);
for(RM_MusicData data : realm.where(RM_MusicData.class).equalTo("playListId", getIntent().getIntExtra("id",0)).findAll()){
mList.add(new MusicData(data));
}
playlistListAdapter = new PlaylistListAdapter(mContext, mList, toolbarTitle.getText());
listView.setAdapter(playlistListAdapter);
}

@OnClick(R.id.toolbar_back) void back(){
onBackPressed();
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/kr/edcan/u_stream/adapter/MainAdapter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package kr.edcan.u_stream.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;

import io.karim.MaterialTabs;
import kr.edcan.u_stream.PlayListActivity;
import kr.edcan.u_stream.R;
import kr.edcan.u_stream.model.RM_PlayListData;
import kr.edcan.u_stream.util.DesignUtil;

/**
Expand Down Expand Up @@ -42,6 +46,16 @@ public Object instantiateItem(View pager, int position) {
v = mInflater.inflate(R.layout.content_main_playlist, null);
GridView gridView = (GridView) v.findViewById(R.id.main_playlist_grid);
gridView.setAdapter(playListGridAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(mContext, PlayListActivity.class);
RM_PlayListData pData = playListGridAdapter.getPlaylist(position);
i.putExtra("title",pData.getTitle());
i.putExtra("id",pData.getId());
mContext.startActivity(i);
}
});
break;
case 2:
v = mInflater.inflate(R.layout.content_main_analog, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.orhanobut.logger.Logger;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmResults;
import kr.edcan.u_stream.R;
import kr.edcan.u_stream.model.RM_MusicData;
Expand All @@ -24,12 +25,14 @@ public class PlayListGridAdapter extends BaseAdapter {
LayoutInflater mInflater;
Context mContext;
RealmResults<RM_PlayListData> pList;
Realm realm;
private Realm realm;
private RealmConfiguration realmConfig;
public PlayListGridAdapter(Context context){
Logger.init("ASDF");
mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
realm = Realm.getInstance(mContext);
realmConfig = new RealmConfiguration.Builder(context).build();
realm = Realm.getInstance(realmConfig);
pList = realm.where(RM_PlayListData.class).findAll();
}
@Override
Expand All @@ -39,7 +42,11 @@ public int getCount() {

@Override
public Object getItem(int position) {
return null;
return pList.get(position);
}

public RM_PlayListData getPlaylist(int position){
return (RM_PlayListData) this.getItem(position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package kr.edcan.u_stream.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;

import kr.edcan.u_stream.R;
import kr.edcan.u_stream.model.MusicData;
import kr.edcan.u_stream.util.DialogUtil;
import kr.edcan.u_stream.util.PlayUtil;

/**
* Created by LNTCS on 2016-03-16.
*/
public class PlaylistListAdapter extends ArrayAdapter<MusicData> {
// 레이아웃 XML을 읽어들이기 위한 객체
private LayoutInflater mInflater;
Context mContext;
String playlistTitle;

public PlaylistListAdapter(Context context, ArrayList<MusicData> object, CharSequence title){
// 상위 클래스의 초기화 과정
// context, 0, 자료구조
super(context,0,object);
mContext = context;
mInflater=(LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.playlistTitle = title.toString();
}

private PlaylistListAdapter getAdapter(){
return this;
}
@Override
public View getView(final int position, View v, ViewGroup parent){
View view = null;
if (v == null) {
view = mInflater.inflate(R.layout.content_playlist_list, null);
view.setTag(position);
} else {
view = v;
}

final MusicData data=this.getItem(position);

if(data!=null){
final TextView title = (TextView)view.findViewById(R.id.playlist_list_title);
TextView uploader = (TextView)view.findViewById(R.id.playlist_list_uploader);
ImageView thumb = (ImageView) view.findViewById(R.id.playlist_list_img);
ImageButton delete = (ImageButton)view.findViewById(R.id.playlist_list_delete);
ImageButton play = (ImageButton)view.findViewById(R.id.playlist_list_play);

title.setText(data.getTitle());
uploader.setText(data.getUploader());
Glide.with(mContext)
.load(data.getThumbnail())
.crossFade()
.into(thumb);

play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Logger.json(new Gson().toJson(data));
PlayUtil.runService(mContext, data, true);
}
});

delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogUtil.deletePlayListDialog(mContext, data, playlistTitle, getAdapter());
}
});
}
return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import kr.edcan.u_stream.R;
import kr.edcan.u_stream.model.MusicData;
import kr.edcan.u_stream.model.RM_PlayListData;
Expand All @@ -29,6 +30,8 @@ public class SearchResultListAdapter extends ArrayAdapter<SearchData> {
private LayoutInflater mInflater;
Context mContext;
int type;
private Realm realm;
private RealmConfiguration realmConfig;
public SearchResultListAdapter(Context context, ArrayList<SearchData> object, int type){
// 상위 클래스의 초기화 과정
// context, 0, 자료구조
Expand Down Expand Up @@ -75,7 +78,8 @@ public void onClick(View v) {
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Realm realm = Realm.getInstance(mContext);
realmConfig = new RealmConfiguration.Builder(mContext).build();
realm = Realm.getInstance(realmConfig);
if (realm.where(RM_PlayListData.class).findAll().size() == 0) {
DialogUtil.addPlayListDialog(mContext, data, type);
} else {
Expand Down
Loading

0 comments on commit 0bd10a0

Please sign in to comment.